Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ extension stat {

var creationDate: Date {
#if canImport(Darwin)
Date(seconds: TimeInterval(st_ctimespec.tv_sec), nanoSeconds: TimeInterval(st_ctimespec.tv_nsec))
Date(seconds: TimeInterval(st_birthtimespec.tv_sec), nanoSeconds: TimeInterval(st_birthtimespec.tv_nsec))
#else
Date(seconds: TimeInterval(st_ctim.tv_sec), nanoSeconds: TimeInterval(st_ctim.tv_nsec))
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,24 @@ private struct FileManagerTests {
}
#endif

@Test(.enabled(if: isDarwin, "Birth time is only exposed on Darwin"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that we should limit this test to Darwin platforms? I know Darwin platforms are the ones that don't pass this test today, but we should expect platforms like Linux and Windows to pass this test as well, right?

func creationDateUsesBirthTime() async throws {
try await FilePlayground {
File("file")
}.test { fileManager in
let attrs1 = try fileManager.attributesOfItem(atPath: "file")
let creation1 = try #require(attrs1[.creationDate] as? Date)

// Mutate metadata to advance ctime without touching birth time
try fileManager.setAttributes([.posixPermissions: 0o600], ofItemAtPath: "file")

let attrs2 = try fileManager.attributesOfItem(atPath: "file")
let creation2 = try #require(attrs2[.creationDate] as? Date)

#expect(creation1 == creation2, "Creation date should remain stable when metadata changes (uses birth time, not ctime)")
}
}

#if canImport(Darwin)
@Test func SearchPathsWithoutExpandingTilde() async throws {
for path in _DarwinSearchPaths(for: .libraryDirectory, in: .userDomainMask, expandTilde: false) {
Expand Down