summaryrefslogtreecommitdiffstats
path: root/src/util/tar.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/tar.rs')
-rw-r--r--src/util/tar.rs18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/util/tar.rs b/src/util/tar.rs
index 885663e..1014abc 100644
--- a/src/util/tar.rs
+++ b/src/util/tar.rs
@@ -1,33 +1,35 @@
use std::{
ffi::CString,
fs::DirBuilder,
- io::{self, Read, Write},
+ io::{self, Read, Result, Write},
os::unix::ffi::OsStrExt,
path::Path,
};
+use walkdir::WalkDir;
+
+use super::unix;
pub fn pack<W: Write, P: AsRef<Path>, E: AsRef<Path>, I: Iterator<Item = E>>(
archive: W,
source: P,
entries: I,
-) -> io::Result<W> {
+) -> Result<W> {
+ let _chdir = unix::chdir(source)?;
+
let mut ar = tar::Builder::new(archive);
ar.mode(tar::HeaderMode::Deterministic);
ar.follow_symlinks(false);
for entry in entries {
- let path = source.as_ref().join(entry.as_ref());
- if path.is_dir() {
- ar.append_dir_all(entry.as_ref(), path)?;
- } else {
- ar.append_path_with_name(path, entry.as_ref())?;
+ for dir_entry in WalkDir::new(entry).sort_by_file_name() {
+ ar.append_path(dir_entry?.path())?;
}
}
ar.into_inner()
}
-pub fn unpack<R: Read, P: AsRef<Path>>(archive: R, dest: P) -> io::Result<()> {
+pub fn unpack<R: Read, P: AsRef<Path>>(archive: R, dest: P) -> Result<()> {
let dest_path = dest.as_ref();
DirBuilder::new().recursive(true).create(dest_path)?;