Skip to content
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

Tracking Issue for feature(file_set_times): FileTimes and File::set_times #98245

Closed
4 tasks done
joshtriplett opened this issue Jun 19, 2022 · 15 comments
Closed
4 tasks done
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@joshtriplett
Copy link
Member

joshtriplett commented Jun 19, 2022

Feature gate: #![feature(file_set_times)]

This is a tracking issue for setting file accesses/modification timestamps via the File::set_times function and associated FileTimes structure.

Public API

// std::fs

#[derive(Copy, Clone, Debug, Default)]
pub struct FileTimes { /* ... */ };

impl FileTimes {
    pub fn new() -> Self;
    pub fn set_accessed(self, t: SystemTime) -> Self;
    pub fn set_modified(self, t: SystemTime) -> Self;
}

impl File {
    pub fn set_times(&self, times: FileTimes) -> std::io::Result<()>;
    pub fn set_modified(&self, t: SystemTime) -> std::io::Result<()>;
}
// std::os::ios::fs
// std::os::macos::fs
// std::os::watchos::fs
// std::os::windows::fs

pub trait FileTimesExt: Sealed {
    fn set_created(self, t: SystemTime) -> Self;
}

impl FileTimesExt for std::fs::FileTimes;

Steps / History

@joshtriplett joshtriplett added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC labels Jun 19, 2022
@m-ou-se
Copy link
Member

m-ou-se commented Jun 20, 2022

I wonder if it would be good to have a file.set_last_modified(time) short-hand for file.set_times(FileTimes::new().set_modified(time)). FileTimes nicely allows platforms to have a FileTimesExt trait to add more times, but it's a bit verbose for simple use cases.

@joshtriplett
Copy link
Member Author

@m-ou-se No fundamental objection, though I don't think we should provide an alias for accessed (less common to set in isolation, and if we had both people might be tempted to call both rather than making one call to set_times).

Also, I'd probably call it set_modified for symmetry with the various uses of modified.

@joshtriplett
Copy link
Member Author

@m-ou-se Done.

@sunfishcode
Copy link
Member

On Unix-family platforms, there's a mechanism for setting a timestamp to the current time (UTIME_NOW), which doesn't appear to be covered in this API. One can get the same effect by using a timestamp of SystemTime::now(); is that fast enough? I expect it is on Linux with the vDSO, but I don't know about other platforms.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 1, 2022
…htriplett

Improve `File::set_times` error handling

Makes `File::set_times` return an error if the `SystemTime` cannot fit into the required type instead of panicking in `FileTimes::set_{accessed,modified}`. Also makes `File::set_times` return an error on Windows if either of the passed times are `0xFFFF_FFFF_FFFF_FFFF`, as [the documentation for `SetFileTime`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfiletime) states that this will prevent operations on the file handle from updating the corresponding file time instead of setting the corresponding file time to that value.

Tracking issue: rust-lang#98245
@sargun
Copy link

sargun commented Oct 12, 2022

One thing I noticed is that there's no way to set the AT_SYMLINK_NOFOLLOW flag for this call. We might want to expose that.

@silence-coding
Copy link

Is there a planned stabilization time for this feature?

@Zerowalker
Copy link

is it possible to at created times here as well?
I know it exists in Windows, not sure about Unix but i would expect it's a thing there as well.

@rbtcollins
Copy link
Contributor

statx is needed for birth time support, and its getting more and more support, but it still pretty new as these things go. https://www.phoronix.com/news/FAT-File-Creation-Birth-5.19 for instance adding support for FAT32 support.

@sargun This seems to be operating on the FD - does NOFOLLOW make any sense when not operating with paths?

compiler-errors added a commit to compiler-errors/rust that referenced this issue Apr 12, 2023
…s, r=Amanieu

Add creation time support to `FileTimes` on apple and windows

Adds support for setting file creation times on platforms which support changing it directly (currently only Apple and Windows). Based on top of rust-lang#110093 (which was split from this PR).

ACP: rust-lang/libs-team#199 (currently still in progress)

Tracking issue: rust-lang#98245

`@rustbot` label +T-libs-api -T-libs
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 13, 2023
…s, r=Amanieu

Add creation time support to `FileTimes` on apple and windows

Adds support for setting file creation times on platforms which support changing it directly (currently only Apple and Windows). Based on top of rust-lang#110093 (which was split from this PR).

ACP: rust-lang/libs-team#199 (currently still in progress)

Tracking issue: rust-lang#98245

`@rustbot` label +T-libs-api -T-libs
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 1, 2023
…riplett

Add 64-bit `time_t` support on 32-bit glibc Linux to `set_times`

Add support to `set_times` for 64-bit `time_t` on 32-bit glibc Linux platforms which have a 32-bit `time_t`. Split from rust-lang#109773.

Tracking issue: rust-lang#98245
bors added a commit to rust-lang-ci/rust that referenced this issue May 19, 2023
… r=Amanieu

Add creation time support to `FileTimes` on apple and windows

Adds support for setting file creation times on platforms which support changing it directly (currently only Apple and Windows). Based on top of rust-lang#110093 (which was split from this PR).

ACP: rust-lang/libs-team#199 (currently still in progress)

Tracking issue: rust-lang#98245

`@rustbot` label +T-libs-api -T-libs
@joshtriplett
Copy link
Member Author

@sunfishcode Might make sense to have an extension for passing UTIME_NOW on platforms that support it.

@joshtriplett
Copy link
Member Author

This has been around for quite a while now, and seems to work as advertised. Shall we stabilize it?

@rfcbot merge

@rfcbot
Copy link

rfcbot commented Sep 6, 2023

Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Sep 6, 2023
@rfcbot rfcbot added the disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. label Sep 6, 2023
@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Oct 5, 2023
@rfcbot
Copy link

rfcbot commented Oct 5, 2023

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Oct 15, 2023
@rfcbot
Copy link

rfcbot commented Oct 15, 2023

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Oct 19, 2023
@ChrisDenton
Copy link
Member

FCP is completed! Anyone feel like making a stabilization PR?

joshtriplett added a commit to joshtriplett/rust that referenced this issue Oct 31, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 1, 2023
…=workingjubilee

Stabilize `file_set_times`

Approved via FCP in rust-lang#98245 .
@chenyukang
Copy link
Member

chenyukang commented Jan 28, 2024

Closing this issue since stabilization PR is finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests