Skip to content

Commit 04493a4

Browse files
authored
Revert "Adopt utimensat for setting file modification dates (#1324)" (#1379)
This reverts commit 9404caa.
1 parent a4b9b0e commit 04493a4

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

Sources/FoundationEssentials/FileManager/FileManager+Files.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -966,14 +966,14 @@ extension _FileManagerImpl {
966966
if let date = attributes[.modificationDate] as? Date {
967967
let (isecs, fsecs) = modf(date.timeIntervalSince1970)
968968
if let tv_sec = time_t(exactly: isecs),
969-
let tv_nsec = Int(exactly: round(fsecs * 1000000000.0)) {
970-
var timespecs = (timespec(), timespec())
971-
timespecs.0.tv_sec = tv_sec
972-
timespecs.0.tv_nsec = tv_nsec
973-
timespecs.1 = timespecs.0
974-
try withUnsafePointer(to: timespecs) {
975-
try $0.withMemoryRebound(to: timespec.self, capacity: 2) {
976-
if utimensat(AT_FDCWD, fileSystemRepresentation, $0, 0) != 0 {
969+
let tv_usec = suseconds_t(exactly: round(fsecs * 1000000.0)) {
970+
var timevals = (timeval(), timeval())
971+
timevals.0.tv_sec = tv_sec
972+
timevals.0.tv_usec = tv_usec
973+
timevals.1 = timevals.0
974+
try withUnsafePointer(to: timevals) {
975+
try $0.withMemoryRebound(to: timeval.self, capacity: 2) {
976+
if utimes(fileSystemRepresentation, $0) != 0 {
977977
throw CocoaError.errorWithFilePath(path, errno: errno, reading: false)
978978
}
979979
}

Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -841,21 +841,6 @@ private struct FileManagerTests {
841841
}
842842
}
843843

844-
@Test func roundtripModificationDate() async throws {
845-
try await FilePlayground {
846-
"foo"
847-
}.test {
848-
// Precision of modification dates is dependent not only on the platform, but on the file system used
849-
// Ensure that roundtripping supports at least millisecond-level precision, but some file systems may support more up to nanosecond precision
850-
let date = Date(timeIntervalSince1970: 10.003)
851-
try $0.setAttributes([.modificationDate : date], ofItemAtPath: "foo")
852-
let readValue = try #require($0.attributesOfItem(atPath: "foo")[.modificationDate], "No value provided for file modification date")
853-
let possibleDate = readValue as? Date
854-
let readDate = try #require(possibleDate, "File modification date was not a date (found type \(type(of: readValue)))")
855-
#expect(abs(readDate.timeIntervalSince1970 - date.timeIntervalSince1970) <= 0.0005, "File modification date (\(readDate.timeIntervalSince1970)) does not match expected modification date (\(date.timeIntervalSince1970))")
856-
}
857-
}
858-
859844
@Test func implicitlyConvertibleFileAttributes() async throws {
860845
try await FilePlayground {
861846
File("foo", attributes: [.posixPermissions : UInt16(0o644)])

0 commit comments

Comments
 (0)