From 3eda66be5fb886e085e503854246e37625378a85 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 26 Sep 2020 13:02:13 -0700 Subject: [PATCH] Foundation: populate the `.creationDate` attribute on non-Linux Ensure that we pass along the creation date from `stat` when querying the attributes of an item. This was being dropped resulting in the creation date for files being unavailable. Fixes: SR-13617 --- Sources/Foundation/FileManager.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/Foundation/FileManager.swift b/Sources/Foundation/FileManager.swift index 26cc13b26a..63500a7eb9 100644 --- a/Sources/Foundation/FileManager.swift +++ b/Sources/Foundation/FileManager.swift @@ -544,6 +544,14 @@ open class FileManager : NSObject { result[.creationDate] = creationDate #else let s = try _lstatFile(atPath: path) + // Darwin provides a `st_ctimespec` rather than the traditional Unix + // `st_ctime` field. Since `st_ctime` is more traditional, special case + // Darwin platforms and convert the timespec to the absolute time. +#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) + result[.creationDate] = Date(timespec: s.st_ctimespec) +#else + result[.creationDate] = Date(timeIntervalSince1970: TimeInterval(s.st_ctime)) +#endif #endif result[.size] = NSNumber(value: UInt64(s.st_size))