-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return file creation times on Linux (using statx) #248
Changes from 2 commits
1307013
0b7dc95
26270cd
c7f65a2
6112c88
29cd8dd
2eca023
5aa6a77
7cee463
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,3 +83,55 @@ fn test_metadata_ext() { | |
); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_metadata_ext_created() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this test in the right / a reasonable place? I wasn't sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good question. metadata-ext.rs is for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
let tmpdir = tmpdir(); | ||
let a = check!(tmpdir.create("a")); | ||
let a_metadata = check!(a.metadata()); | ||
|
||
let modified = check!(a_metadata.modified()); | ||
let tolerance = std::time::Duration::from_secs(10); | ||
let expected = (modified - tolerance)..(modified + tolerance); | ||
|
||
// If the standard library supports file creation times, then cap-std | ||
// should too. | ||
sunfishcode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let std_supports_created = matches!( | ||
a.into_std().metadata(), | ||
Ok(m) if m.created().is_ok(), | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, that makes more sense than what I had done. Updated. |
||
|
||
if std_supports_created { | ||
let created = check!(a_metadata.created()); | ||
assert!( | ||
expected.contains(&created), | ||
"expected File creation time near {:#?} but got {:#?}", | ||
modified, | ||
created, | ||
); | ||
|
||
let tmpdir_metadata = check!(tmpdir.dir_metadata()); | ||
let created = check!(tmpdir_metadata.created()); | ||
assert!( | ||
expected.contains(&created), | ||
"expected Dir creation time near {:#?} but got {:#?}", | ||
modified, | ||
created, | ||
); | ||
|
||
let mut entries = check!(tmpdir.entries()); | ||
if let Some(a) = entries.next() { | ||
let a = check!(a); | ||
assert_eq!(a.file_name(), "a"); | ||
let metadata = check!(a.metadata()); | ||
let created = check!(metadata.created()); | ||
assert!( | ||
expected.contains(&created), | ||
"expected DirEntry creation time near {:#?} but got {:#?}", | ||
modified, | ||
created, | ||
); | ||
} | ||
assert!(entries.next().is_none(), "unexpected dir entry"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea when the rustix version will be updated? I don't have a sense of how big that is, so I didn't want to add it to this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The biggest thing for cap-std is that there are some semver incompatibilities between versions of io-lifetimes, which is tracking changes from I/O safety stabilization. Fortunately, the FCP looks to be almost done. Once it's done, I plan to do an io-lifetimes release and then a rustix 0.35 release, and then update cap-std and various other things.