MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / negative_file_timestamp

Function negative_file_timestamp

tests/fs/negative_timestamp.rs:4–54  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2#[cfg(not(target_os = "cygwin"))]
3#[test]
4fn negative_file_timestamp() {
5 use rustix::fs::{
6 fstat, futimens, lstat, open, stat, statat, AtFlags, Mode, OFlags, Timespec, Timestamps,
7 CWD,
8 };
9
10 let tmp = tempfile::tempdir().unwrap();
11
12 let file = open(
13 tmp.path().join("foo"),
14 OFlags::CREATE | OFlags::WRONLY,
15 Mode::RWXU,
16 )
17 .unwrap();
18
19 let stamps = Timestamps {
20 last_modification: Timespec {
21 tv_sec: -20,
22 tv_nsec: 12,
23 },
24 last_access: Timespec {
25 tv_sec: -23,
26 tv_nsec: 14,
27 },
28 };
29 futimens(&file, &stamps).unwrap();
30
31 let st = fstat(file).unwrap();
32 assert_eq!(st.st_mtime, -20);
33 assert_eq!(st.st_mtime_nsec, 12);
34 assert_eq!(st.st_atime, -23);
35 assert_eq!(st.st_atime_nsec, 14);
36
37 let st = stat(tmp.path().join("foo")).unwrap();
38 assert_eq!(st.st_mtime, -20);
39 assert_eq!(st.st_mtime_nsec, 12);
40 assert_eq!(st.st_atime, -23);
41 assert_eq!(st.st_atime_nsec, 14);
42
43 let st = lstat(tmp.path().join("foo")).unwrap();
44 assert_eq!(st.st_mtime, -20);
45 assert_eq!(st.st_mtime_nsec, 12);
46 assert_eq!(st.st_atime, -23);
47 assert_eq!(st.st_atime_nsec, 14);
48
49 let st = statat(CWD, tmp.path().join("foo"), AtFlags::empty()).unwrap();
50 assert_eq!(st.st_mtime, -20);
51 assert_eq!(st.st_mtime_nsec, 12);
52 assert_eq!(st.st_atime, -23);
53 assert_eq!(st.st_atime_nsec, 14);
54}

Callers

nothing calls this directly

Calls 7

openFunction · 0.50
futimensFunction · 0.50
fstatFunction · 0.50
statFunction · 0.50
lstatFunction · 0.50
statatFunction · 0.50
pathMethod · 0.45

Tested by

no test coverage detected