Skip to content

On MacOS std::fs::copy does not modify the timestamp of the destination #115982

Open

Description

@dpc

I was just debugging different behavior between Linux and MacOS builds in our CI, and it turns out, it came to sqlite-sys crate using build.rs script that uses std::fs::copy, which on MacOS seems to be using fcopyfile call which preserves the modification, access, and creation timestamps from the source file to the destination file by default.

This is an inconsistency with implementations on other platforms, I believe.

It seems that COPYFILE_STAT flag could be turned off on that call, but that will also prevent mode from being copied, which seems copied on other implementations. So AFAICT making behavior consistent would cost an extra syscall.

Unless I'm mistaken somewhere altogether (happens a lot), at very least this should be explicitly documented.

Personally, I would prefer this being made consistent. As unreliable as they can sometimes be mtimes are often used for things like caching, and it's no fun to hunt down weird caching bugs etc. that happen only on one platform.

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 19, 2023
  2. added
    O-macosOperating system: macOS
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 19, 2023
  3. workingjubilee commented on Sep 20, 2023

    @workingjubilee
    Member

    The implementation should simply start using clonefile when #104385 lands. I believe the mtime behavior of clonefile is correct here. And if it's not: CoW file copying still goes brrr.

  4. alexandru0-dev commented on Mar 31, 2024

    @alexandru0-dev

    any updates?

  5. bardiharborow commented on Aug 24, 2026

    @bardiharborow
    Contributor

    @rustbot label +A-filesystem +O-apple

  6. added
    O-appleOperating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS)
    on Aug 24, 2026
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

    A-filesystemArea: `std::fs`C-bugCategory: This is a bug.O-appleOperating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS)O-macosOperating system: macOST-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions