-
Notifications
You must be signed in to change notification settings - Fork 717
feat: Add associated constants UTIME_OMIT UTIME_NOW to TimeSpec
#1879
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
Conversation
|
|
asomers
left a comment
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.
Do you think it would be more natural to change the arguments into an enum like this:
pub enum UtimeSpec {
Omit,
Now,
Set(TimeSpec)
}Or would that just be unnecessarily complicated?
src/sys/stat.rs
Outdated
| libc::timespec { | ||
| tv_sec: 0, | ||
| tv_nsec: libc::UTIME_OMIT, | ||
| }, | ||
| libc::timespec { | ||
| tv_sec: 0, | ||
| tv_nsec: libc::UTIME_OMIT, | ||
| }, |
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.
| libc::timespec { | |
| tv_sec: 0, | |
| tv_nsec: libc::UTIME_OMIT, | |
| }, | |
| libc::timespec { | |
| tv_sec: 0, | |
| tv_nsec: libc::UTIME_OMIT, | |
| }, | |
| libc::timespec { | |
| tv_sec: 0, | |
| tv_nsec: libc::UTIME_OMIT, | |
| .. | |
| }, | |
| libc::timespec { | |
| tv_sec: 0, | |
| tv_nsec: libc::UTIME_OMIT, | |
| .. | |
| }, |
See #1886 for the reason why.
Honestly, this interface looks great, a better way to go! |
16fd0b7 to
0198ead
Compare
adf1b3e to
891a3fe
Compare
891a3fe to
392dc17
Compare
Issue filed. This PR involves two syscalls:
Redox does not support For #[inline]
#[cfg(target_os = "redox")]
pub fn futimens(fd: RawFd, atime: &TimeSpec, mtime: &TimeSpec) -> Result<()> {
let times: [libc::timespec; 2] = [*atime.as_ref(), *mtime.as_ref()];
let res = unsafe { libc::futimens(fd, ×[0]) };
|
utimensat and futimens optional
utimensat and futimens optionalutimensat and futimens
392dc17 to
3a54f42
Compare
utimensat and futimensutimensat and futimens
3a54f42 to
f56e6fa
Compare
asomers
left a comment
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.
This looks good. But before we merge it, I just have to ask a question: does the TimestampSpec abstraction create too much overhead? I think it's nice and ergonomic. But a zero-cost alternative would simply be to leave the old interface as it was, and add constants like this:
pub const UTIME_OMIT: libc::timespec {tv_sec: 0, tv_nsec: libc::UTIME_OMIT}that the user could pass in to futimens.
Let's compare these two interfaces: NEW interface// To leave timestamps unchanged
futimens(&file, &TimestampSpec::Omit, &TimestampSpec::Omit).unwrap();
// To update timestamps to NOW
futimens(&file, &TimestampSpec::Now, &TimestampSpec::Now).unwrap();
// To set timestamps to specific values, e.g., UNIX epoch
let timespec = TimeSpec::zero();
futimens(
&file,
&TimestampSpec::Set(timespec),
&TimestampSpec::Set(timespec),
)
.unwrap();OLD interface, with
|
f56e6fa to
bcfcd7d
Compare
|
Update on the that Redox (relibc) issue, reply from developers of Redox:
|
|
I just ran into this issue, so I'm glad to see it's being worked on :) A third option for the API might be to define associated constants for impl TimeSpec {
pub const NOW: TimeSpec = TimeSpec::new(0, libc::UTIME_NOW);
pub const OMIT: TimeSpec = TimeSpec::new(0, libc::UTIME_OMIT);
}It would also be more self-documenting than reexporting It would look like this when used: // To leave timestamps unchanged
futimens(&file, &TimeSpec::OMIT, &TimeSpec::OMIT).unwrap();
// To update timestamps to NOW
futimens(&file, &TimeSpec::NOW, &TimeSpec::NOW).unwrap();
// To set timestamps to specific values, e.g., UNIX epoch
let timespec = TimeSpec::zero();
futimens(
&file,
×pec,
×pec,
)
.unwrap(); |
bcfcd7d to
fc3822b
Compare
utimensat and futimensUTIME_OMIT UTIME_NOW for TimeSpec
UTIME_OMIT UTIME_NOW for TimeSpecUTIME_OMIT UTIME_NOW to TimeSpec
|
|
||
| /// Change the access and modification times of the file specified by a file descriptor. | ||
| /// | ||
| /// If you want to set the timestamp to now, use `TimeSpec::UTIME_NOW`. Use |
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.
Cannot use "[`TimeSpec::UTIME_NOW`]" because redox does not have it
Since we can add some breaking changes in the following 0.27 release, I made this PR.
What this PR does
atime,mtimearguments ofutimenstat(2)andfutimens(2)toOption<&TimeSpec>, when set toNone, the corresponding timestamp remains unchanged.libc::UTIME_NOWinnix::sys::statmodule so that users can directly use it when they want to update timestamps to the special valueNowgethostname(2)inREADME.mdto the UNIX one (from Open Group)Fixes #1834
cc @sargun