Skip to content

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

Closed
@beetrees

Description

@beetrees

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard libraries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions