@@ -683,3 +683,48 @@ extension FileSystemProtocol {
683683 }
684684 }
685685}
686+
687+ // MARK: - File attributes
688+
689+ @available ( macOS 10 . 15 , iOS 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
690+ extension FileSystemProtocol {
691+ /// Sets the file's last access and last data modification times to the given times.
692+ ///
693+ /// - Parameters:
694+ /// - path: The path of the file to modify.
695+ /// - lastAccess: The new value of the file's last access time, as time elapsed since the Epoch.
696+ /// - lastDataModification: The new value of the file's last data modification time, as time elapsed since the Epoch.
697+ public func setTimes(
698+ forFileAt path: FilePath ,
699+ lastAccess: FileInfo . Timespec ? ,
700+ lastDataModification: FileInfo . Timespec ?
701+ ) async throws {
702+ try await self . withFileHandle ( forReadingAt: path) { handle in
703+ try await handle. setTimes ( lastAccess: lastAccess, lastDataModification: lastDataModification)
704+ }
705+ }
706+
707+ /// Sets the file's last access time to the given time.
708+ ///
709+ /// - Parameters:
710+ /// - path: The path of the file to modify.
711+ /// - time: The time to which the file's last access time should be set.
712+ public func setLastAccessTime(
713+ forFileAt path: FilePath ,
714+ to time: FileInfo . Timespec
715+ ) async throws {
716+ try await self . setTimes ( forFileAt: path, lastAccess: time, lastDataModification: nil )
717+ }
718+
719+ /// Sets the file's last data modification time to the given time.
720+ ///
721+ /// - Parameters:
722+ /// - path: The path of the file to modify.
723+ /// - time: The time to which the file's last data modification time should be set.
724+ public func setLastDataModificationTime(
725+ forFileAt path: FilePath ,
726+ to time: FileInfo . Timespec
727+ ) async throws {
728+ try await self . setTimes ( forFileAt: path, lastAccess: nil , lastDataModification: time)
729+ }
730+ }
0 commit comments