extern crate std;
use subprocess;
use unpacker;
struct Tar {
}
impl unpacker::Unpacker for Tar {
fn unpack(&self, in_file: &std::path::Path, out_dir: &std::path::Path) -> Result<std::path::PathBuf, unpacker::Error> {
info!("Unpacking (tar) {:?} in {:?}", in_file, out_dir);
unpacker::check_unpack_args(in_file, out_dir)?;
let in_path_str = match in_file.to_str() {
Some(path) => path,
None => { return Err(unpacker::PathError); }
};
if ! out_dir.exists() {
std::fs::create_dir_all(out_dir)?;
}
let mut cmd = subprocess::new("tar");
cmd.stdout(std::process::Stdio::null());
cmd.current_dir(&out_dir);
cmd.arg("-xf");
cmd.arg(in_path_str);
subprocess::run(&mut cmd)?;
std::fs::remove_file(in_file)?;
Ok(out_dir.to_path_buf())
}
}
pub fn new() -> Box<unpacker::Unpacker> {
Box::new(Tar {
})
}
pub fn name_get() -> &'static str {
"tar"
}