catar/decoder.rs: improve restore_sequential
This commit is contained in:
parent
b6ebfb8dab
commit
c6a0d3fc6b
|
@ -142,17 +142,25 @@ impl <'a, R: Read + Seek> CaTarDecoder<'a, R> {
|
||||||
check_ca_header::<CaFormatEntry>(&head, CA_FORMAT_ENTRY)?;
|
check_ca_header::<CaFormatEntry>(&head, CA_FORMAT_ENTRY)?;
|
||||||
let entry: CaFormatEntry = self.read_item()?;
|
let entry: CaFormatEntry = self.read_item()?;
|
||||||
|
|
||||||
let is_dir = ((entry.mode as u32) & libc::S_IFMT) == libc::S_IFDIR;
|
let mode = entry.mode as u32; //fixme: upper 32bits?
|
||||||
|
|
||||||
|
let is_dir = (mode & libc::S_IFMT) == libc::S_IFDIR;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let head: CaFormatHeader = self.read_item()?;
|
let head: CaFormatHeader = self.read_item()?;
|
||||||
match head.htype {
|
match head.htype {
|
||||||
CA_FORMAT_SYMLINK => {
|
CA_FORMAT_SYMLINK => {
|
||||||
|
if ((mode & libc::S_IFMT) != libc::S_IFLNK) {
|
||||||
|
bail!("detected unexpected symlink item.");
|
||||||
|
}
|
||||||
let target = self.read_symlink(head.size)?;
|
let target = self.read_symlink(head.size)?;
|
||||||
println!("TARGET: {:?}", target);
|
println!("TARGET: {:?}", target);
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
CA_FORMAT_FILENAME => {
|
CA_FORMAT_FILENAME => {
|
||||||
if !is_dir { bail!("onyl directoriy entries may contain file names."); }
|
if !is_dir {
|
||||||
|
bail!("onyl directoriy entries may contain file names.");
|
||||||
|
}
|
||||||
let name = self.read_filename(head.size)?;
|
let name = self.read_filename(head.size)?;
|
||||||
path.push(name);
|
path.push(name);
|
||||||
println!("NAME: {:?}", path);
|
println!("NAME: {:?}", path);
|
||||||
|
@ -160,12 +168,18 @@ impl <'a, R: Read + Seek> CaTarDecoder<'a, R> {
|
||||||
path.pop();
|
path.pop();
|
||||||
}
|
}
|
||||||
CA_FORMAT_PAYLOAD => {
|
CA_FORMAT_PAYLOAD => {
|
||||||
|
if ((mode & libc::S_IFMT) != libc::S_IFREG) {
|
||||||
|
bail!("detected enexpected paylod item.");
|
||||||
|
}
|
||||||
println!("Skip Payload");
|
println!("Skip Payload");
|
||||||
if head.size < HEADER_SIZE { bail!("detected short payload"); }
|
if head.size < HEADER_SIZE { bail!("detected short payload"); }
|
||||||
self.reader.seek(SeekFrom::Current((head.size - HEADER_SIZE) as i64))?;
|
self.reader.seek(SeekFrom::Current((head.size - HEADER_SIZE) as i64))?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
CA_FORMAT_GOODBYE => {
|
CA_FORMAT_GOODBYE => {
|
||||||
|
if !is_dir {
|
||||||
|
bail!("onyl directoriy entries may contain goodbye tables.");
|
||||||
|
}
|
||||||
println!("Skip Goodbye");
|
println!("Skip Goodbye");
|
||||||
if head.size < HEADER_SIZE { bail!("detected short goodbye table"); }
|
if head.size < HEADER_SIZE { bail!("detected short goodbye table"); }
|
||||||
self.reader.seek(SeekFrom::Current((head.size - HEADER_SIZE) as i64))?;
|
self.reader.seek(SeekFrom::Current((head.size - HEADER_SIZE) as i64))?;
|
||||||
|
|
Loading…
Reference in New Issue