mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
touch: add --ref as an alias (#2641)
This commit is contained in:
parent
2170d81621
commit
ed258e3c9c
2 changed files with 18 additions and 9 deletions
|
@ -6,7 +6,7 @@
|
||||||
// For the full copyright and license information, please view the LICENSE file
|
// For the full copyright and license information, please view the LICENSE file
|
||||||
// that was distributed with this source code.
|
// that was distributed with this source code.
|
||||||
|
|
||||||
// spell-checker:ignore (ToDO) filetime strptime utcoff strs datetime MMDDhhmm
|
// spell-checker:ignore (ToDO) filetime strptime utcoff strs datetime MMDDhhmm clapv
|
||||||
|
|
||||||
pub extern crate filetime;
|
pub extern crate filetime;
|
||||||
|
|
||||||
|
@ -176,6 +176,7 @@ pub fn uu_app() -> App<'static, 'static> {
|
||||||
Arg::with_name(options::sources::REFERENCE)
|
Arg::with_name(options::sources::REFERENCE)
|
||||||
.short("r")
|
.short("r")
|
||||||
.long(options::sources::REFERENCE)
|
.long(options::sources::REFERENCE)
|
||||||
|
.alias("ref") // clapv3
|
||||||
.help("use this file's times instead of the current time")
|
.help("use this file's times instead of the current time")
|
||||||
.value_name("FILE"),
|
.value_name("FILE"),
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,6 +6,7 @@ use self::touch::filetime::{self, FileTime};
|
||||||
extern crate time;
|
extern crate time;
|
||||||
|
|
||||||
use crate::common::util::*;
|
use crate::common::util::*;
|
||||||
|
use std::fs::remove_file;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn get_file_times(at: &AtPath, path: &str) -> (FileTime, FileTime) {
|
fn get_file_times(at: &AtPath, path: &str) -> (FileTime, FileTime) {
|
||||||
|
@ -323,7 +324,8 @@ fn test_touch_no_dereference() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_touch_reference() {
|
fn test_touch_reference() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let scenario = TestScenario::new("touch");
|
||||||
|
let (at, mut _ucmd) = (scenario.fixtures.clone(), scenario.ucmd());
|
||||||
let file_a = "test_touch_reference_a";
|
let file_a = "test_touch_reference_a";
|
||||||
let file_b = "test_touch_reference_b";
|
let file_b = "test_touch_reference_b";
|
||||||
let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000");
|
let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000");
|
||||||
|
@ -331,15 +333,21 @@ fn test_touch_reference() {
|
||||||
at.touch(file_a);
|
at.touch(file_a);
|
||||||
set_file_times(&at, file_a, start_of_year, start_of_year);
|
set_file_times(&at, file_a, start_of_year, start_of_year);
|
||||||
assert!(at.file_exists(file_a));
|
assert!(at.file_exists(file_a));
|
||||||
|
for &opt in &["-r", "--ref", "--reference"] {
|
||||||
|
scenario
|
||||||
|
.ccmd("touch")
|
||||||
|
.args(&[opt, file_a, file_b])
|
||||||
|
.succeeds()
|
||||||
|
.no_stderr();
|
||||||
|
|
||||||
ucmd.args(&["-r", file_a, file_b]).succeeds().no_stderr();
|
assert!(at.file_exists(file_b));
|
||||||
|
|
||||||
assert!(at.file_exists(file_b));
|
let (atime, mtime) = get_file_times(&at, file_b);
|
||||||
|
assert_eq!(atime, mtime);
|
||||||
let (atime, mtime) = get_file_times(&at, file_b);
|
assert_eq!(atime, start_of_year);
|
||||||
assert_eq!(atime, mtime);
|
assert_eq!(mtime, start_of_year);
|
||||||
assert_eq!(atime, start_of_year);
|
let _ = remove_file(file_b);
|
||||||
assert_eq!(mtime, start_of_year);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue