You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to basically tar up a directory as is by walking a tree and adding the files therein, but am noticing that the symlinks that exists in the folder are duplicated as an actual full dereferenced copy in the archive. Is there a sane way to add symlinked files? Been grepping the tests and docs, but not really gotten any wiser.
This is what I've got:
// pipe builder -> encoder -> filelet file = File::create(&tarball)?;letmut encoder = GzEncoder::new(file,Compression::Default);// encoder writes fileletmut builder = tar::Builder::new(&mut encoder);// tar builder writes to encoderlet files = WalkDir::new("OUTPUT").min_depth(1).into_iter().filter_map(|e| e.ok()).filter(|e| !e.path().is_dir());// ignore directories (these are created anyway)for f in files {let pth = f.path().strip_prefix("OUTPUT").unwrap();debug!("-> {}", pth.display());letmut f = File::open(f.path())?;
builder.append_file(pth,&mut f)?;}
which causes symlinks to be copied.
From the looks of it one can do something with an explicit Header and set_link_names and using builder.append(), when something is a symlink. So have tried doing a match on fs::symlink_metadata(pth), and use builder.append() when it was a link using:
letmut h = Header::new_gnu();
h.set_path(pth).unwrap();
h.set_size(0);let data :&[u8] = &[];let f = fs::read_link(pth)?;
h.set_link_name(f)?;
builder.append(&h, data)?;
and the builder lets me do this, but this creates a damaged archive that tar tvf complains about. Any help / documentation on adding links would be great. I just want to do the equivalent of tar czvf mytar.tar OUTPUT
The text was updated successfully, but these errors were encountered:
Hi,
I'm trying to basically tar up a directory as is by walking a tree and adding the files therein, but am noticing that the symlinks that exists in the folder are duplicated as an actual full dereferenced copy in the archive. Is there a sane way to add symlinked files? Been grepping the tests and docs, but not really gotten any wiser.
This is what I've got:
which causes symlinks to be copied.
From the looks of it one can do something with an explicit
Header
andset_link_names
and usingbuilder.append()
, when something is a symlink. So have tried doing a match onfs::symlink_metadata(pth)
, and usebuilder.append()
when it was a link using:and the builder lets me do this, but this creates a damaged archive that
tar tvf
complains about. Any help / documentation on adding links would be great. I just want to do the equivalent oftar czvf mytar.tar OUTPUT
The text was updated successfully, but these errors were encountered: