mac: tidy menu and gateway support
This commit is contained in:
@@ -4,22 +4,23 @@ enum LogLocator {
|
||||
private static let logDir = URL(fileURLWithPath: "/tmp/clawdis")
|
||||
private static let stdoutLog = logDir.appendingPathComponent("clawdis-stdout.log")
|
||||
|
||||
private static func modificationDate(for url: URL) -> Date {
|
||||
(try? url.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast
|
||||
}
|
||||
|
||||
/// Returns the newest log file under /tmp/clawdis/ (rolling or stdout), or nil if none exist.
|
||||
static func bestLogFile() -> URL? {
|
||||
let fm = FileManager.default
|
||||
let files = (try? fm.contentsOfDirectory(
|
||||
at: logDir,
|
||||
at: self.logDir,
|
||||
includingPropertiesForKeys: [.contentModificationDateKey],
|
||||
options: [.skipsHiddenFiles])) ?? []
|
||||
|
||||
return files
|
||||
.filter { $0.lastPathComponent.hasPrefix("clawdis") && $0.pathExtension == "log" }
|
||||
.sorted { lhs, rhs in
|
||||
let lDate = (try? lhs.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast
|
||||
let rDate = (try? rhs.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast
|
||||
return lDate > rDate
|
||||
.max { lhs, rhs in
|
||||
self.modificationDate(for: lhs) < self.modificationDate(for: rhs)
|
||||
}
|
||||
.first
|
||||
}
|
||||
|
||||
/// Path to use for launchd stdout/err.
|
||||
|
||||
Reference in New Issue
Block a user