Skip to content

Improve the doc for utimensat(3) and futimens(3) #1834

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

Closed
SteveLauC opened this issue Oct 5, 2022 · 2 comments · Fixed by #1879
Closed

Improve the doc for utimensat(3) and futimens(3) #1834

SteveLauC opened this issue Oct 5, 2022 · 2 comments · Fixed by #1879

Comments

@SteveLauC
Copy link
Member

SteveLauC commented Oct 5, 2022

One advantage of utimensat(3) and futimens(3) over utimes(2) is that they can just set one timestamp at a time.

Cite the man page:

If the tv_nsec field of a timespec structure has the special value UTIME_NOW, the file's relevant timestamp shall be set to the greatest value supported by the file system that is not greater than the current time. If the tv_nsec field has the special value UTIME_OMIT, the file's relevant timestamp shall not be changed. In either case, the tv_sec field shall be ignored.

Say I wanna update atime and leave mtime unchanged, if using utimes(2), I have to retrieve the previous mtime using stat(2) or something similar, but using utimensat(3) or futimens(3), I can just easily set the tv_nsec field of that timestamp to UTIME_OMIT.

So I think this feature deserves to be documented.

@SteveLauC SteveLauC changed the title Improve the doc for utimenstat(3) and futimens(3) Improve the doc for utimensat(3) and futimens(3) Oct 5, 2022
@rtzoeller
Copy link
Collaborator

It seems like there are two reasonable options:

  1. Make atime and mtime type Option<&TimeSpec>, and set UTIME_OMIT internally.
  2. Re-export UTIME_OMIT from the nix crate, and document it better.

Option 1 seem Rustier, but Option 2 avoids breaking API compatibility with the existing function. @asomers @SteveLauC @sargun thoughts?

@SteveLauC
Copy link
Member Author

Option 1 is a more natural way. But to avoid making existing user programs broken, what about adopting option 2 in the interim, leaving a TODO in it, and changing to option 1 when we can introduce breaking APIs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants