-
Notifications
You must be signed in to change notification settings - Fork 56
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
Enable setting file times for any writable files #105
base: main
Are you sure you want to change the base?
Enable setting file times for any writable files #105
Conversation
a788cb7
to
b0f1845
Compare
Changes since last push:
|
I ignored I'll change a few lines, but the bulk will remain identical. |
b0f1845
to
f3e0ec6
Compare
I verified that this works on Linux 4.9 and Linux 6.6.
This is a POSIX-feature according to https://pubs.opengroup.org/onlinepubs/9699919799/ By changing mod.rs, I verified that this works on Linux 4.9 and Linux 6.6.
This is a POSIX-feature according to https://pubs.opengroup.org/onlinepubs/9699919799/ By changing mod.rs, I verified that this works on Linux 4.9 and Linux 6.6.
f3e0ec6
to
814b337
Compare
Changes since initial version:
|
@alexcrichton Hi! Can I ask you to look into this, and perhaps merge it? This feature would be really useful. |
@@ -486,6 +517,62 @@ mod tests { | |||
Ok(()) | |||
} | |||
|
|||
#[test] | |||
#[cfg(unix)] | |||
// TODO: Do Android and MacOS implement this feature of utimensat? |
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.
Android: Yes.
Darwin: Not immediately clear at a glance.
- https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/bsd/sys/stat.h#L582-L583
- https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/tests/utimensat.c
- https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/tests/netbsd_utimensat.c
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.
Then I guess it's safest to implement it just the way that this PR already does: Defer to the non-NULL variant, and improve it in a later PR if/when more is known about what Darwin accepts.
This PR enables calling (f)utime(n)s(at) in a special way that was not possible before.
In particular, POSIX specifies that when
times
is a nullptr, then utimensat only requires that the caller has write access to the file. This cannot be emulated by any other function of this crate, as they always pass a userspace-providedtimes
struct, which requires the caller to be the owner of the file.This PR adds two new functions to the API:
set_file_times_now(p: &Path, follow_symlink: bool)
andset_file_handle_times_now(f: &fs::File)
.Fun fact: I'm trying to work on the Rust coreutils, and this feature is required to implement
touch
in a way that passes thetouch/now-owned-by-other
test.