1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

Merge pull request #1319 from rivy/fix.touch

fix ~ touch: fix and test for windows
This commit is contained in:
Alex Lyon 2019-04-08 15:16:26 -07:00 committed by GitHub
commit cefbe6c1f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 29 deletions

View file

@ -56,7 +56,6 @@ fuchsia = [
"nice", "nice",
"pathchk", "pathchk",
"stdbuf", "stdbuf",
"touch",
"tty", "tty",
"uname", "uname",
"unlink", "unlink",
@ -69,6 +68,7 @@ generic = [
"hostname", "hostname",
"nproc", "nproc",
"sync", "sync",
"touch",
"whoami", "whoami",
"redox_generic" "redox_generic"
] ]

View file

@ -18,7 +18,7 @@ extern crate uucore;
use filetime::*; use filetime::*;
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::{self, Error}; use std::io::Error;
use std::path::Path; use std::path::Path;
static NAME: &str = "touch"; static NAME: &str = "touch";
@ -42,31 +42,6 @@ macro_rules! local_tm_to_filetime(
}) })
); );
macro_rules! to_timeval {
($ft:expr) => (
timeval {
tv_sec: $ft.seconds() as time_t,
tv_usec: ($ft.nanoseconds() / 1000) as suseconds_t,
}
)
}
#[cfg(unix)]
fn set_symlink_times(p: &str, atime: FileTime, mtime: FileTime) -> io::Result<()> {
use std::ffi::CString;
use uucore::libc::{lutimes, suseconds_t, time_t, timeval};
let times = [to_timeval!(atime), to_timeval!(mtime)];
let p = try!(CString::new(p));
return unsafe {
if lutimes(p.as_ptr() as *const _, times.as_ptr()) == 0 {
Ok(())
} else {
Err(io::Error::last_os_error())
}
};
}
pub fn uumain(args: Vec<String>) -> i32 { pub fn uumain(args: Vec<String>) -> i32 {
let mut opts = getopts::Options::new(); let mut opts = getopts::Options::new();
@ -204,7 +179,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
} }
if matches.opt_present("h") { if matches.opt_present("h") {
if let Err(e) = set_symlink_times(path, atime, mtime) { if let Err(e) = set_symlink_file_times(path, atime, mtime) {
show_warning!("cannot touch '{}': {}", path, e); show_warning!("cannot touch '{}': {}", path, e);
} }
} else { } else {

View file

@ -26,7 +26,6 @@ unix_only! {
"pathchk", test_pathchk; "pathchk", test_pathchk;
"pinky", test_pinky; "pinky", test_pinky;
"stdbuf", test_stdbuf; "stdbuf", test_stdbuf;
"touch", test_touch;
"unlink", test_unlink; "unlink", test_unlink;
"who", test_who; "who", test_who;
// Be aware of the trailing semicolon after the last item // Be aware of the trailing semicolon after the last item
@ -86,6 +85,7 @@ generic! {
"tac", test_tac; "tac", test_tac;
"tail", test_tail; "tail", test_tail;
"test", test_test; "test", test_test;
"touch", test_touch;
"tr", test_tr; "tr", test_tr;
"true", test_true; "true", test_true;
"truncate", test_truncate; "truncate", test_truncate;