mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 21:17:46 +00:00
fix gnu/tests/touch/60-seconds
This commit is contained in:
parent
2b11d77395
commit
31c28eeaa9
2 changed files with 32 additions and 4 deletions
|
@ -17,6 +17,7 @@ use filetime::*;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use time::macros::{format_description, time};
|
use time::macros::{format_description, time};
|
||||||
|
use time::Duration;
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
use uucore::error::{FromIo, UError, UResult, USimpleError};
|
use uucore::error::{FromIo, UError, UResult, USimpleError};
|
||||||
use uucore::format_usage;
|
use uucore::format_usage;
|
||||||
|
@ -345,16 +346,25 @@ fn parse_timestamp(s: &str) -> UResult<FileTime> {
|
||||||
format = YYYYMMDDHHMM_DOT_SS_FORMAT;
|
format = YYYYMMDDHHMM_DOT_SS_FORMAT;
|
||||||
ts = "20".to_owned() + &ts;
|
ts = "20".to_owned() + &ts;
|
||||||
}
|
}
|
||||||
if (format == YYYYMMDDHHMM_DOT_SS_FORMAT || format == YYMMDDHHMM_DOT_SS_FORMAT)
|
|
||||||
|
let leap_sec = if (format == YYYYMMDDHHMM_DOT_SS_FORMAT || format == YYMMDDHHMM_DOT_SS_FORMAT)
|
||||||
&& ts.ends_with(".60")
|
&& ts.ends_with(".60")
|
||||||
{
|
{
|
||||||
// Work around to disable leap seconds
|
// Work around to disable leap seconds
|
||||||
|
// Used in gnu/tests/touch/60-seconds
|
||||||
ts = ts.replace(".60", ".59");
|
ts = ts.replace(".60", ".59");
|
||||||
}
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
let tm = time::PrimitiveDateTime::parse(&ts, &format)
|
let tm = time::PrimitiveDateTime::parse(&ts, &format)
|
||||||
.map_err(|_| USimpleError::new(1, format!("invalid date ts format {}", ts.quote())))?;
|
.map_err(|_| USimpleError::new(1, format!("invalid date ts format {}", ts.quote())))?;
|
||||||
|
let mut local = to_local(tm);
|
||||||
let local = to_local(tm);
|
if leap_sec {
|
||||||
|
// We are dealing with a leap second, add it
|
||||||
|
local = local.saturating_add(Duration::SECOND);
|
||||||
|
}
|
||||||
let ft = local_dt_to_filetime(local);
|
let ft = local_dt_to_filetime(local);
|
||||||
|
|
||||||
// // We have to check that ft is valid time. Due to daylight saving
|
// // We have to check that ft is valid time. Due to daylight saving
|
||||||
|
|
|
@ -603,3 +603,21 @@ fn test_no_dereference_no_file() {
|
||||||
.stderr_contains("setting times of 'not-a-file-1': No such file or directory")
|
.stderr_contains("setting times of 'not-a-file-1': No such file or directory")
|
||||||
.stderr_contains("setting times of 'not-a-file-2': No such file or directory");
|
.stderr_contains("setting times of 'not-a-file-2': No such file or directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_touch_leap_second() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let file = "test_touch_leap_sec";
|
||||||
|
|
||||||
|
ucmd.args(&["-t", "197001010000.60", file])
|
||||||
|
.succeeds()
|
||||||
|
.no_stderr();
|
||||||
|
|
||||||
|
assert!(at.file_exists(file));
|
||||||
|
|
||||||
|
let epoch = str_to_filetime("%Y%m%d%H%M", "197001010000");
|
||||||
|
let (atime, mtime) = get_file_times(&at, file);
|
||||||
|
assert_eq!(atime, mtime);
|
||||||
|
assert_eq!(atime.unix_seconds() - epoch.unix_seconds(), 60);
|
||||||
|
assert_eq!(mtime.unix_seconds() - epoch.unix_seconds(), 60);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue