Skip to content

Commit

Permalink
Merge pull request #7545 from nextcloud/bugfix/final-final-mc-fix-pls
Browse files Browse the repository at this point in the history
Fix mac-crafter codesign executable check path building
  • Loading branch information
claucambra authored Nov 21, 2024
2 parents 3378126 + 07d6456 commit 4e0e2f4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 13 additions & 3 deletions admin/osx/mac-crafter/Sources/Utils/Codesign.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ func recursivelyCodesign(
}

for case let enumeratedItem as String in pathEnumerator {
let isExecutableFile = try isExecutable(fm.currentDirectoryPath + "/" + path + "/" + enumeratedItem)
let enumeratedItemPath = "\(path)/\(enumeratedItem)"
let isExecutableFile = try isExecutable(enumeratedItemPath)
guard isLibrary(enumeratedItem) || isAppExtension(enumeratedItem) || isExecutableFile else {
continue
}
try codesign(identity: identity, path: "\(path)/\(enumeratedItem)", options: options)
try codesign(identity: identity, path: enumeratedItemPath, options: options)
}
}

Expand Down Expand Up @@ -144,6 +145,15 @@ func codesignClientAppBundle(
}

// Now we do the final codesign bit
let binariesDir = "\(clientContentsDir)/MacOS"
print("Code-signing Nextcloud Desktop Client binaries...")
try recursivelyCodesign(path: "\(clientContentsDir)/MacOS/", identity: codeSignIdentity)
try recursivelyCodesign(path: binariesDir, identity: codeSignIdentity)

guard let appName = clientAppDir.components(separatedBy: "/").last, clientAppDir.hasSuffix(".app") else {
throw AppBundleSigningError.couldNotEnumerate("Failed to determine main executable name.")
}

// Sign the main executable last
let mainExecutableName = String(appName.dropLast(".app".count))
try codesign(identity: codeSignIdentity, path: "\(binariesDir)/\(mainExecutableName)")
}
5 changes: 4 additions & 1 deletion admin/osx/mac-crafter/Sources/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ struct Codesign: ParsableCommand {
var codeSignIdentity: String

mutating func run() throws {
try codesignClientAppBundle(at: appBundlePath, withCodeSignIdentity: codeSignIdentity)
let absolutePath = appBundlePath.hasPrefix("/")
? appBundlePath
: "\(FileManager.default.currentDirectoryPath)/\(appBundlePath)"
try codesignClientAppBundle(at: absolutePath, withCodeSignIdentity: codeSignIdentity)
}
}

Expand Down

0 comments on commit 4e0e2f4

Please sign in to comment.