Closed
Description
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
- Implementation: Support setting file accessed/modified timestamps #98246Final comment period (FCP)Stabilization PR
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
m-ou-se commentedon Jun 20, 2022
I wonder if it would be good to have a
file.set_last_modified(time)
short-hand forfile.set_times(FileTimes::new().set_modified(time))
.FileTimes
nicely allows platforms to have aFileTimesExt
trait to add more times, but it's a bit verbose for simple use cases.joshtriplett commentedon Jun 20, 2022
@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 toset_times
).Also, I'd probably call it
set_modified
for symmetry with the various uses ofmodified
.joshtriplett commentedon Jun 20, 2022
@m-ou-se Done.
sunfishcode commentedon Jun 23, 2022
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 ofSystemTime::now()
; is that fast enough? I expect it is on Linux with the vDSO, but I don't know about other platforms.File::set_times
error handling #101675Rollup merge of rust-lang#101675 - beetrees:set-times-no-panic, r=jos…
sargun commentedon 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 commentedon Oct 14, 2022
Is there a planned stabilization time for this feature?
Zerowalker commentedon Jan 8, 2023
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 commentedon Feb 10, 2023
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?
FileTimes
on apple and windows #109773FileTimes
on supported platforms rust-lang/libs-team#19932 remaining items