Skip to content

Add support for setting file creation time to the unstable FileTimes on supported platforms #199

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
beetrees opened this issue Mar 30, 2023 · 1 comment
Labels
ACP-accepted API Change Proposal is accepted (seconded with no objections) api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api

Comments

@beetrees
Copy link

Proposal

Problem statement

The unstable FileTimes can currently only set the file modification and accessed times. It should also allow changing the file creation time when the platform supports this. Currently only Windows and Apple platforms support setting creation time directly.

FreeBSD and NetBSD will both set the creation time to the modification time if the requested modification time is earlier than the current creation time; this allows the creation time to be set as long as the desired creation time is earlier than the current creation time by calling futimens twice, once to set the desired creation time, and a second time to set the desired modification time. I'm not sure whether this is worth providing a dedicated API for given that it can be achieved through multiple calls to File::set_modified, so I've left it out of the initial implementation.

Motivation, use-cases

Setting creation time is useful when synchronising files between different locations by allowing the file creation time to be synchronised correctly. This API fills in a gap in the current (unstable) API surface, in that accessed, modified and created times can all be retrieved but only accessed and modified times can be set.

Solution sketches

I've implemented this in rust-lang/rust#109773 as a platform-specific extension trait. An alternative would be to make the method always available and return an error if the platform doesn't support setting creation time (similar to how creation time is retrieved with the Metadata::created method); however given the extremely limited platform support the extension trait implementation seemed like a better choice.

Links and related work

Tracking issue for FileTimes: rust-lang/rust#98245
.NET's implementation on Windows and macOS.

What happens now?

This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.

@beetrees beetrees added api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api labels Mar 30, 2023
@Amanieu Amanieu added the initial-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. label Apr 8, 2023
@Amanieu
Copy link
Member

Amanieu commented Apr 8, 2023

Seconded. This is a useful API addition.

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
@joshtriplett joshtriplett added the ACP-accepted API Change Proposal is accepted (seconded with no objections) label May 19, 2023
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
oli-obk pushed a commit to oli-obk/miri that referenced this issue May 23, 2023
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 #110093 (which was split from this PR).

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

Tracking issue: #98245

`@rustbot` label +T-libs-api -T-libs
thomcc pushed a commit to tcdi/postgrestd that referenced this issue Jul 18, 2023
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 #110093 (which was split from this PR).

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

Tracking issue: #98245

`@rustbot` label +T-libs-api -T-libs
@dtolnay dtolnay removed the initial-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. label Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ACP-accepted API Change Proposal is accepted (seconded with no objections) api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api
Projects
None yet
Development

No branches or pull requests

4 participants