Skip to content

Commit

Permalink
fixup! Fix handling contents added after header creation
Browse files Browse the repository at this point in the history
  • Loading branch information
elbe0046 committed Mar 4, 2022
1 parent 9edb4c2 commit ab642af
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/builder.rs
Expand Up @@ -108,7 +108,7 @@ impl<W: Write> Builder<W> {
/// let data = ar.into_inner().unwrap();
/// ```
pub fn append<R: Read>(&mut self, header: &Header, mut data: R) -> io::Result<()> {
append(self.get_mut(), header, &mut data)
append(self.get_mut(), header, &mut data).map(|_| ())
}

/// Adds a new entry to this archive with the specified path.
Expand Down Expand Up @@ -406,7 +406,7 @@ impl<W: Write> Builder<W> {
}
}

fn append(mut dst: &mut dyn Write, header: &Header, mut data: &mut dyn Read) -> io::Result<()> {
fn append(mut dst: &mut dyn Write, header: &Header, mut data: &mut dyn Read) -> io::Result<u64> {
dst.write_all(header.as_bytes())?;
let len = io::copy(&mut data, &mut dst)?;

Expand All @@ -417,7 +417,7 @@ fn append(mut dst: &mut dyn Write, header: &Header, mut data: &mut dyn Read) ->
dst.write_all(&buf[..remaining as usize])?;
}

Ok(())
Ok(len)
}

fn append_path_with_name(
Expand All @@ -444,8 +444,7 @@ fn append_path_with_name(
};
let ar_name = name.unwrap_or(path);
if stat.is_file() {
let file = fs::File::open(path)?;
append_fs(dst, ar_name, &stat, &mut file.take(stat.len()), mode, None)
append_fs(dst, ar_name, &stat, &mut fs::File::open(path)?, mode, None)
} else if stat.is_dir() {
append_fs(dst, ar_name, &stat, &mut io::empty(), mode, None)
} else if stat.file_type().is_symlink() {
Expand Down Expand Up @@ -521,7 +520,7 @@ fn append_file(
mode: HeaderMode,
) -> io::Result<()> {
let stat = file.metadata()?;
append_fs(dst, path, &stat, &mut file.take(stat.len()), mode, None)
append_fs(dst, path, &stat, file, mode, None)
}

fn append_dir(
Expand Down Expand Up @@ -615,7 +614,9 @@ fn append_fs(
prepare_header_link(dst, &mut header, link_name)?;
}
header.set_cksum();
append(dst, &header, read)
let size = append(dst, &header, read)?;
header.set_size(size);
Ok(())
}

fn append_dir_all(
Expand Down

0 comments on commit ab642af

Please sign in to comment.