@@ -64,6 +64,62 @@ extension FileSystem {
6464final class FileSystemTests : XCTestCase {
6565 var fs : FileSystem { . shared }
6666
67+ func testSetLastAccessAndDataModificationTimes( ) async throws {
68+ let path = try await self . fs. temporaryFilePath ( )
69+ try await self . fs. withFileHandle ( forWritingAt: path, options: . newFile( replaceExisting: false ) ) { _ in }
70+
71+ let originalInfo = try await self . fs. info ( forFileAt: path)
72+ let originalLastAccessTime = originalInfo? . lastAccessTime
73+ let originalLastDataModificationTime = originalInfo? . lastDataModificationTime
74+
75+ let newAccessTime = FileInfo . Timespec ( seconds: 10 , nanoseconds: 5 )
76+ let newDataModTime = FileInfo . Timespec ( seconds: 20 , nanoseconds: 25 )
77+
78+ try await self . fs. setTimes ( forFileAt: path, lastAccess: newAccessTime, lastDataModification: newDataModTime)
79+
80+ let newInfo = try await self . fs. info ( forFileAt: path)
81+ XCTAssertEqual ( newInfo? . lastAccessTime, newAccessTime)
82+ XCTAssertEqual ( newInfo? . lastDataModificationTime, newDataModTime)
83+ XCTAssertNotEqual ( newInfo? . lastAccessTime, originalLastAccessTime)
84+ XCTAssertNotEqual ( newInfo? . lastDataModificationTime, originalLastDataModificationTime)
85+
86+ try await self . fs. removeItem ( at: path)
87+ }
88+
89+ func testSetLastAccessTime( ) async throws {
90+ let path = try await self . fs. temporaryFilePath ( )
91+ try await self . fs. withFileHandle ( forWritingAt: path, options: . newFile( replaceExisting: false ) ) { _ in }
92+
93+ let originalInfo = try await self . fs. info ( forFileAt: path)
94+ let originalLastDataModificationTime = originalInfo? . lastDataModificationTime
95+
96+ let newAccessTime = FileInfo . Timespec ( seconds: 10 , nanoseconds: 5 )
97+ try await self . fs. setLastAccessTime ( forFileAt: path, to: newAccessTime)
98+
99+ let newInfo = try await self . fs. info ( forFileAt: path)
100+ XCTAssertEqual ( newInfo? . lastAccessTime, newAccessTime)
101+ XCTAssertEqual ( newInfo? . lastDataModificationTime, originalLastDataModificationTime)
102+
103+ try await self . fs. removeItem ( at: path)
104+ }
105+
106+ func testSetLastDataModificationTime( ) async throws {
107+ let path = try await self . fs. temporaryFilePath ( )
108+ try await self . fs. withFileHandle ( forWritingAt: path, options: . newFile( replaceExisting: false ) ) { _ in }
109+
110+ let originalInfo = try await self . fs. info ( forFileAt: path)
111+ let originalLastAccessTime = originalInfo? . lastAccessTime
112+
113+ let newDataModTime = FileInfo . Timespec ( seconds: 20 , nanoseconds: 25 )
114+ try await self . fs. setLastDataModificationTime ( forFileAt: path, to: newDataModTime)
115+
116+ let newInfo = try await self . fs. info ( forFileAt: path)
117+ XCTAssertEqual ( newInfo? . lastDataModificationTime, newDataModTime)
118+ XCTAssertEqual ( newInfo? . lastAccessTime, originalLastAccessTime)
119+
120+ try await self . fs. removeItem ( at: path)
121+ }
122+
67123 func testOpenFileForReading( ) async throws {
68124 try await self . fs. withFileHandle ( forReadingAt: . testDataReadme) { file in
69125 let info = try await file. info ( )
0 commit comments