You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Return file creation times on Linux (using statx) (#248)
* Return file creation times on Linux (using statx)
Rust's standard library returns file creation times on Linux (at least with
glibc), and now rust-std will too.
File creation times are available on Linux via the `statx` syscall (not
`fstatat`), introduced in kernel 4.11, which was released in April 2017. The
Rust standard library already uses `statx` on Linux with glibc.
Making cap-std support file creation times on Linux required two changes:
1. `File::metadata()` uses the standard library (which uses `statx`), but this
wouldn't ever copy over the created field on Linux. Now, any time the
created field is set in the std Metadata struct, it's also set in the
cap-primitives Metadata, regardless of platform.
2. `stat_unchecked` is used in several places, including fetching DirEntry
metadata. Before, it called `fstatat` directly. Now, it calls `statx` on
Linux when available, and it falls back to `fstatat` otherwise. Fortunately,
Dan Gohman (@sunfishcode) had already added a method to convert `statx`
results in commit d1fa735 (PR #105) in 2020.
This commit also adds a new test to make sure file creation times are set in
cap-std Metadata if they are set in std Metadata.
* stat_unchecked: Add backticks to comments from PR suggestions
Co-authored-by: Dan Gohman <[email protected]>
* stat_unchecked: Reflow comment
* stat_unchecked: Rewrite match statement for clarity
* Rewrite file created times test to do exact comparisons against std
* Move file created times test into fs_additional
* Expand file created times test to check entire Metadata
* stat_unchecked: Handle EPERM errors from statx
* fs_additional: Fix non-Unix test build in metadata test
I had used `cfg!(unix)` instead of `#[cfg(unix)]` in 2eca023, which doesn't
conditionally compile out the Unix-specific code.
Co-authored-by: Dan Gohman <[email protected]>
0 commit comments