src/pxar/decoder.rs: rustfmt fixups

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
This commit is contained in:
Christian Ebner 2019-09-03 13:17:02 +02:00 committed by Dietmar Maurer
parent 3fa71727ee
commit 3626ac611f
1 changed files with 38 additions and 24 deletions

View File

@ -12,7 +12,6 @@ use std::path::{Path, PathBuf};
use std::ffi::OsString;
pub struct DirectoryEntry {
start: u64,
end: u64,
@ -30,10 +29,8 @@ pub struct Decoder<R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> {
const HEADER_SIZE: u64 = std::mem::size_of::<PxarHeader>() as u64;
const GOODBYE_ITEM_SIZE: u64 = std::mem::size_of::<PxarGoodbyeItem>() as u64;
impl <R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<R, F> {
impl<R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<R, F> {
pub fn new(mut reader: R, callback: F) -> Result<Self, Error> {
let root_end = reader.seek(SeekFrom::End(0))?;
Ok(Self {
@ -61,11 +58,7 @@ impl <R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<R, F> {
Ok(pos)
}
pub fn restore(
&mut self,
dir: &DirectoryEntry,
path: &Path,
) -> Result<(), Error> {
pub fn restore(&mut self, dir: &DirectoryEntry, path: &Path) -> Result<(), Error> {
let start = dir.start;
self.seek(SeekFrom::Start(start))?;
@ -76,7 +69,6 @@ impl <R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<R, F> {
}
fn read_directory_entry(&mut self, start: u64, end: u64) -> Result<DirectoryEntry, Error> {
self.seek(SeekFrom::Start(start))?;
let head: PxarHeader = self.inner.read_item()?;
@ -106,7 +98,6 @@ impl <R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<R, F> {
}
pub fn list_dir(&mut self, dir: &DirectoryEntry) -> Result<Vec<DirectoryEntry>, Error> {
let start = dir.start;
let end = dir.end;
@ -121,31 +112,50 @@ impl <R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<R, F> {
let item: PxarGoodbyeItem = self.inner.read_item()?;
if item.hash != PXAR_GOODBYE_TAIL_MARKER {
bail!("missing goodbye tail marker for object [{}..{}]", start, end);
bail!(
"missing goodbye tail marker for object [{}..{}]",
start,
end
);
}
let goodbye_table_size = item.size;
if goodbye_table_size < (HEADER_SIZE + GOODBYE_ITEM_SIZE) {
bail!("short goodbye table size for object [{}..{}]", start, end);
}
let goodbye_inner_size = goodbye_table_size - HEADER_SIZE - GOODBYE_ITEM_SIZE;
if (goodbye_inner_size % GOODBYE_ITEM_SIZE) != 0 {
bail!("wrong goodbye inner table size for entry [{}..{}]", start, end);
bail!(
"wrong goodbye inner table size for entry [{}..{}]",
start,
end
);
}
let goodbye_start = end - goodbye_table_size;
if item.offset != (goodbye_start - start) {
println!("DEBUG: {} {}", u64::from_le(item.offset), goodbye_start - start);
bail!("wrong offset in goodbye tail marker for entry [{}..{}]", start, end);
println!(
"DEBUG: {} {}",
u64::from_le(item.offset),
goodbye_start - start
);
bail!(
"wrong offset in goodbye tail marker for entry [{}..{}]",
start,
end
);
}
self.seek(SeekFrom::Start(goodbye_start))?;
let head: PxarHeader = self.inner.read_item()?;
if head.htype != PXAR_GOODBYE {
bail!("wrong goodbye table header type for entry [{}..{}]", start, end);
bail!(
"wrong goodbye table header type for entry [{}..{}]",
start,
end
);
}
if head.size != goodbye_table_size {
@ -154,18 +164,24 @@ impl <R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<R, F> {
let mut range_list = Vec::new();
for i in 0..goodbye_inner_size/GOODBYE_ITEM_SIZE {
for i in 0..goodbye_inner_size / GOODBYE_ITEM_SIZE {
let item: PxarGoodbyeItem = self.inner.read_item()?;
if item.offset > (goodbye_start - start) {
bail!("goodbye entry {} offset out of range [{}..{}] {} {} {}",
i, start, end, item.offset, goodbye_start, start);
bail!(
"goodbye entry {} offset out of range [{}..{}] {} {} {}",
i,
start,
end,
item.offset,
goodbye_start,
start
);
}
let item_start = goodbye_start - item.offset;
let item_end = item_start + item.size;
if item_end > goodbye_start {
bail!("goodbye entry {} end out of range [{}..{}]",
i, start, end);
bail!("goodbye entry {} end out of range [{}..{}]", i, start, end);
}
range_list.push((item_start, item_end));
@ -188,13 +204,11 @@ impl <R: Read + Seek, F: Fn(&Path) -> Result<(), Error>> Decoder<R, F> {
prefix: &mut PathBuf,
dir: &DirectoryEntry,
) -> Result<(), Error> {
let mut list = self.list_dir(dir)?;
list.sort_unstable_by(|a, b| a.filename.cmp(&b.filename));
for item in &list {
prefix.push(item.filename.clone());
let mode = item.entry.mode as u32;