mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-28 19:58:56 +03:00
Do not rely on FileManager's isExecutableFile, check manually for Mach-O executable type
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
92f0cd96ef
commit
e8ac221769
1 changed files with 20 additions and 10 deletions
|
@ -32,11 +32,21 @@ func isAppExtension(_ path: String) -> Bool {
|
||||||
path.hasSuffix(".appex")
|
path.hasSuffix(".appex")
|
||||||
}
|
}
|
||||||
|
|
||||||
func isExecutable(_ path: String) -> Bool {
|
func isExecutable(_ path: String) throws -> Bool {
|
||||||
let fm = FileManager.default
|
let outPipe = Pipe()
|
||||||
var isDir: ObjCBool = false
|
let errPipe = Pipe()
|
||||||
let exists = fm.fileExists(atPath: path, isDirectory: &isDir)
|
let task = Process()
|
||||||
return fm.isExecutableFile(atPath: path) && !isDir.boolValue && exists
|
task.standardOutput = outPipe
|
||||||
|
task.standardError = errPipe
|
||||||
|
|
||||||
|
let command = "file \"\(path)\""
|
||||||
|
guard run("/bin/zsh", ["-c", command], task: task) == 0 else {
|
||||||
|
throw CodeSigningError.failedToCodeSign("Failed to determine if \(path) is an executable.")
|
||||||
|
}
|
||||||
|
|
||||||
|
let outputData = outPipe.fileHandleForReading.readDataToEndOfFile()
|
||||||
|
let output = String(data: outputData, encoding: .utf8) ?? ""
|
||||||
|
return output.contains("Mach-O 64-bit executable")
|
||||||
}
|
}
|
||||||
|
|
||||||
func codesign(identity: String, path: String, options: String = defaultCodesignOptions) throws {
|
func codesign(identity: String, path: String, options: String = defaultCodesignOptions) throws {
|
||||||
|
@ -60,11 +70,11 @@ func recursivelyCodesign(
|
||||||
}
|
}
|
||||||
|
|
||||||
for case let enumeratedItem as String in pathEnumerator {
|
for case let enumeratedItem as String in pathEnumerator {
|
||||||
guard isLibrary(enumeratedItem) ||
|
let isExecutableFile = try isExecutable(fm.currentDirectoryPath + "/" + path + "/" + enumeratedItem)
|
||||||
isAppExtension(enumeratedItem) ||
|
guard isLibrary(enumeratedItem) || isAppExtension(enumeratedItem) || isExecutableFile else {
|
||||||
isExecutable(enumeratedItem)
|
continue
|
||||||
else { continue }
|
}
|
||||||
try codesign(identity: identity, path: "\(path)/\(enumeratedItem)")
|
try codesign(identity: identity, path: "\(path)/\(enumeratedItem)", options: options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue