mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 21:47:46 +00:00
cp: use filetime to set timestamps.
This commit is contained in:
parent
03432db951
commit
38dd8c5836
2 changed files with 5 additions and 13 deletions
|
@ -17,6 +17,7 @@ walkdir = "1.0.7"
|
||||||
clap = "2.20.0"
|
clap = "2.20.0"
|
||||||
quick-error = "1.1.0"
|
quick-error = "1.1.0"
|
||||||
uucore = { path="../uucore" }
|
uucore = { path="../uucore" }
|
||||||
|
filetime = "0.1"
|
||||||
|
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
ioctl-sys = "0.5.2"
|
ioctl-sys = "0.5.2"
|
||||||
|
|
17
src/cp/cp.rs
17
src/cp/cp.rs
|
@ -13,6 +13,8 @@
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
extern crate walkdir;
|
extern crate walkdir;
|
||||||
|
extern crate filetime;
|
||||||
|
use filetime::FileTime;
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
#[macro_use] extern crate ioctl_sys;
|
#[macro_use] extern crate ioctl_sys;
|
||||||
#[macro_use] extern crate uucore;
|
#[macro_use] extern crate uucore;
|
||||||
|
@ -790,19 +792,8 @@ fn copy_attribute(source: &Path, dest: &Path, attribute: &Attribute) -> CopyResu
|
||||||
fs::set_permissions(dest, metadata.permissions()).context(context)?;
|
fs::set_permissions(dest, metadata.permissions()).context(context)?;
|
||||||
},
|
},
|
||||||
Attribute::Timestamps => {
|
Attribute::Timestamps => {
|
||||||
let meta = fs::metadata(source)?;
|
let metadata = fs::metadata(source)?;
|
||||||
let modified = meta.modified()?;
|
filetime::set_file_times(Path::new(dest), FileTime::from_last_access_time(&metadata), FileTime::from_last_modification_time(&metadata))?;
|
||||||
let accessed = meta.accessed()?;
|
|
||||||
let src_path = CString::new(source.as_os_str().to_str().unwrap()).unwrap();
|
|
||||||
let dest_path = CString::new(dest.as_os_str().to_str().unwrap()).unwrap();
|
|
||||||
unsafe {
|
|
||||||
let mut stat: libc::stat = mem::zeroed();
|
|
||||||
libc::stat(src_path.as_ptr(), &mut stat);
|
|
||||||
libc::utime(dest_path.as_ptr(), &libc::utimbuf{
|
|
||||||
actime: stat.st_atime,
|
|
||||||
modtime: stat.st_mtime
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Attribute::Context => return Err(Error::NotImplemented("preserving context not implemented".to_string())),
|
Attribute::Context => return Err(Error::NotImplemented("preserving context not implemented".to_string())),
|
||||||
Attribute::Links => return Err(Error::NotImplemented("preserving links not implemented".to_string())),
|
Attribute::Links => return Err(Error::NotImplemented("preserving links not implemented".to_string())),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue