Major update for stability

This commit is contained in:
Mark Gregory
2026-09-08 15:22:19 +01:00
parent 3b95f53a25
commit b2f3c5aef6
24 changed files with 1059 additions and 212 deletions
+23 -6
View File
@@ -1,12 +1,29 @@
import Foundation
enum RsyncLocator {
static let candidates = [
"/opt/homebrew/bin/rsync",
"/usr/local/bin/rsync",
"/usr/bin/rsync"
]
static func locate() -> String {
let candidates = [
"/opt/homebrew/bin/rsync",
"/usr/local/bin/rsync",
"/usr/bin/rsync"
]
return candidates.first(where: { FileManager.default.isExecutableFile(atPath: $0) }) ?? "/usr/bin/rsync"
candidates.first(where: isTrustedExecutableCandidate) ?? "/usr/bin/rsync"
}
static func isTrustedExecutableCandidate(_ path: String) -> Bool {
let manager = FileManager.default
guard manager.isExecutableFile(atPath: path) else { return false }
let resolved = URL(fileURLWithPath: path).resolvingSymlinksInPath().path
var isDirectory: ObjCBool = false
guard manager.fileExists(atPath: resolved, isDirectory: &isDirectory), !isDirectory.boolValue else { return false }
do {
let attributes = try manager.attributesOfItem(atPath: resolved)
return attributes[.type] as? FileAttributeType == .typeRegular
} catch {
return false
}
}
}