Commit 90a03741 authored by Bryan Blanchard's avatar Bryan Blanchard

Read symlinks from tar header and recreate

parent 5fade3cf
......@@ -8,7 +8,7 @@ extern crate libflate;
use std::{env, process};
use std::io::{stdin, stdout, stderr, copy, Error, ErrorKind, Result, Read, Write, BufReader};
use std::fs::{self, File};
use std::os::unix::fs::OpenOptionsExt;
use std::os::unix::fs::{OpenOptionsExt, symlink};
use std::path::{Path, PathBuf};
use std::str::FromStr;
......@@ -61,6 +61,14 @@ fn list(tar: &str) -> Result<()> {
}
}
fn create_symlink(link: PathBuf, target: &Path) -> Result<()> {
//delete existing file to make way for symlink
if link.exists() {
fs::remove_file(link.clone()).expect(&format!("could not overwrite: {:?}", link));
}
symlink(target, link)
}
fn extract_inner<T: Read>(ar: &mut Archive<T>, verbose: bool, strip: usize) -> Result<()> {
for entry_result in try!(ar.entries()) {
let mut entry = try!(entry_result);
......@@ -99,6 +107,11 @@ fn extract_inner<T: Read>(ar: &mut Archive<T>, verbose: bool, strip: usize) -> R
EntryType::Directory => {
try!(fs::create_dir_all(&path));
},
EntryType::Symlink => {
if let Some(target) = entry.link_name().expect(&format!("Can't parse symlink target for: {:?}", path)) {
try!(create_symlink(path, &target))
}
},
other => {
panic!("Unsupported entry type {:?}", other);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment