Commit c0eafc2a authored by Jeremy Soller's avatar Jeremy Soller Committed by GitHub

Merge pull request #29 from ids1024/time

tar: set file times
parents eb391bfc 4c1a796c
......@@ -81,7 +81,11 @@ libflate = "0.1.4"
pager = { git = "https://github.com/redox-os/libpager.git" }
raw-cpuid = "2.0"
redox_syscall = "0.1"
tar = { git = "https://github.com/redox-os/tar-rs.git" }
tar = { git = "https://github.com/alexcrichton/tar-rs.git" }
filetime = "0.1.10"
termion = { git = "https://github.com/redox-os/termion.git", branch = "redox_termios" }
rust-lzma = "0.2"
tree_magic = "0.2"
[replace]
"filetime:0.1.10" = { git = "https://github.com/alexcrichton/filetime.git" }
......@@ -4,6 +4,7 @@ extern crate tar;
extern crate tree_magic;
extern crate lzma;
extern crate libflate;
extern crate filetime;
use std::{env, process};
use std::io::{stdin, stdout, stderr, copy, Error, ErrorKind, Result, Read, Write, BufReader};
......@@ -15,6 +16,7 @@ use std::str::FromStr;
use tar::{Archive, Builder, EntryType};
use lzma::LzmaReader;
use libflate::gzip::Decoder as GzipDecoder;
use filetime::FileTime;
fn create_inner<T: Write>(input: &str, ar: &mut Builder<T>) -> Result<()> {
if try!(fs::metadata(input)).is_dir() {
......@@ -88,21 +90,27 @@ fn extract_inner<T: Read>(ar: &mut Archive<T>, verbose: bool, strip: usize) -> R
match entry.header().entry_type() {
EntryType::Regular => {
let mut file = {
if let Some(parent) = path.parent() {
try!(fs::create_dir_all(parent));
}
try!(
fs::OpenOptions::new()
.read(true)
.write(true)
.truncate(true)
.create(true)
.mode(entry.header().mode().unwrap_or(644))
.open(&path)
)
};
try!(copy(&mut entry, &mut file));
{
let mut file = {
if let Some(parent) = path.parent() {
try!(fs::create_dir_all(parent));
}
try!(
fs::OpenOptions::new()
.read(true)
.write(true)
.truncate(true)
.create(true)
.mode(entry.header().mode().unwrap_or(644))
.open(&path)
)
};
try!(copy(&mut entry, &mut file));
}
if let Ok(mtime) = entry.header().mtime() {
let mtime = FileTime::from_seconds_since_1970(mtime, 0);
try!(filetime::set_file_times(&path, mtime, mtime));
}
},
EntryType::Directory => {
try!(fs::create_dir_all(&path));
......
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