From a63548eea059951bd260afdf91ffee0bbbf5c81d Mon Sep 17 00:00:00 2001 From: Tim Andersson Date: Wed, 12 Apr 2023 14:32:33 +0200 Subject: [PATCH 1/2] Use attachment timestamp as modification date of exported attachment file This allows users of `xcparse screenshots` to order the exported screenshots by the screenshots' timestamps in Finder, for example. This makes it much easier to understand how the UI tests progressed. --- Sources/XCParseCore/XCResultToolCommand.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sources/XCParseCore/XCResultToolCommand.swift b/Sources/XCParseCore/XCResultToolCommand.swift index 58d0b1c..361758b 100644 --- a/Sources/XCParseCore/XCResultToolCommand.swift +++ b/Sources/XCParseCore/XCResultToolCommand.swift @@ -63,11 +63,13 @@ open class XCResultToolCommand { var id: String = "" var outputPath: String = "" var type: ExportType = ExportType.file + private let timestamp: Date? public init(withXCResult xcresult: XCResult, id: String, outputPath: String, type: ExportType) { self.id = id self.outputPath = outputPath self.type = type + self.timestamp = nil var processArgs = xcresultToolArguments processArgs.append(contentsOf: ["export", @@ -89,6 +91,7 @@ open class XCResultToolCommand { let attachmentOutputPath = URL.init(fileURLWithPath: outputPath).appendingPathComponent(filename) self.outputPath = attachmentOutputPath.path } + self.timestamp = attachment.timestamp var processArgs = xcresultToolArguments processArgs.append(contentsOf: ["export", @@ -100,6 +103,14 @@ open class XCResultToolCommand { let process = TSCBasic.Process(arguments: processArgs) super.init(withXCResult: xcresult, process: process) } + + public override func run() -> ProcessResult? { + let superResult = super.run() + if superResult == nil { return nil } + guard let timestamp else { return superResult } + try? FileManager.default.setAttributes([.modificationDate: timestamp as Any], ofItemAtPath: outputPath) + return superResult + } } open class Get: XCResultToolCommand { From 5ed439a3aef9933edf3e4104bd91b1b2ebd2df6c Mon Sep 17 00:00:00 2001 From: Tim Andersson Date: Wed, 19 Apr 2023 12:57:41 +0200 Subject: [PATCH 2/2] Replace usage of Swift 5.7 syntax to keep Swift 5 compatibility --- Sources/XCParseCore/XCResultToolCommand.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/XCParseCore/XCResultToolCommand.swift b/Sources/XCParseCore/XCResultToolCommand.swift index 361758b..5b7b6a6 100644 --- a/Sources/XCParseCore/XCResultToolCommand.swift +++ b/Sources/XCParseCore/XCResultToolCommand.swift @@ -107,7 +107,7 @@ open class XCResultToolCommand { public override func run() -> ProcessResult? { let superResult = super.run() if superResult == nil { return nil } - guard let timestamp else { return superResult } + guard let timestamp = timestamp else { return superResult } try? FileManager.default.setAttributes([.modificationDate: timestamp as Any], ofItemAtPath: outputPath) return superResult }