Skip to content

Commit fd7c1e9

Browse files
authored
Merge pull request swiftlang#2884 from compnerd/populate-creationDate
Foundation: populate the `.creationDate` attribute on Windows
2 parents 82b8fa2 + 3eda66b commit fd7c1e9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Sources/Foundation/FileManager.swift

+8
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,14 @@ open class FileManager : NSObject {
544544
result[.creationDate] = creationDate
545545
#else
546546
let s = try _lstatFile(atPath: path)
547+
// Darwin provides a `st_ctimespec` rather than the traditional Unix
548+
// `st_ctime` field. Since `st_ctime` is more traditional, special case
549+
// Darwin platforms and convert the timespec to the absolute time.
550+
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
551+
result[.creationDate] = Date(timespec: s.st_ctimespec)
552+
#else
553+
result[.creationDate] = Date(timeIntervalSince1970: TimeInterval(s.st_ctime))
554+
#endif
547555
#endif
548556

549557
result[.size] = NSNumber(value: UInt64(s.st_size))

0 commit comments

Comments
 (0)