Skip to content

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

Closed
@joshtriplett

Description

@joshtriplett
Member

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

Activity

added
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
on Jun 19, 2022
m-ou-se

m-ou-se commented on Jun 20, 2022

@m-ou-se
Member

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

joshtriplett commented on Jun 20, 2022

@joshtriplett
MemberAuthor

@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

joshtriplett commented on Jun 20, 2022

@joshtriplett
MemberAuthor

@m-ou-se Done.

sunfishcode

sunfishcode commented on Jun 23, 2022

@sunfishcode
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.

added a commit that references this issue on Oct 1, 2022

Rollup merge of rust-lang#101675 - beetrees:set-times-no-panic, r=jos…

21fc218
sargun

sargun commented on Oct 12, 2022

@sargun

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

silence-coding commented on Oct 14, 2022

@silence-coding

Is there a planned stabilization time for this feature?

Zerowalker

Zerowalker commented on Jan 8, 2023

@Zerowalker

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

rbtcollins commented on Feb 10, 2023

@rbtcollins
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?

32 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @joshtriplett@chenyukang@rbtcollins@sargun@m-ou-se

        Issue actions

          Tracking Issue for `feature(file_set_times)`: `FileTimes` and `File::set_times` · Issue #98245 · rust-lang/rust