From: Claudio Cambra Date: Thu, 21 Nov 2024 10:27:52 +0000 (+0800) Subject: Allow using an external task for running commands in mac-crafter run command X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~5^2~24^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=92f0cd96effaf11b5b4a056302e33a150ce8a5ac;p=nextcloud-desktop.git Allow using an external task for running commands in mac-crafter run command Signed-off-by: Claudio Cambra --- diff --git a/admin/osx/mac-crafter/Sources/Utils/Shell.swift b/admin/osx/mac-crafter/Sources/Utils/Shell.swift index 1d7a35522..8c1570c5e 100644 --- a/admin/osx/mac-crafter/Sources/Utils/Shell.swift +++ b/admin/osx/mac-crafter/Sources/Utils/Shell.swift @@ -14,40 +14,39 @@ import Foundation -var task: Process? +weak var globalTaskRef: Process? @discardableResult func run( _ launchPath: String, _ args: [String], env: [String: String]? = nil, - quiet: Bool = false + quiet: Bool = false, + task: Process = Process() ) -> Int32 { - defer { task = nil } - task = Process() - + globalTaskRef = task signal(SIGINT) { _ in - task?.terminate() // Send terminate signal to the task - exit(0) // Exit the script after cleanup + globalTaskRef?.terminate() // Send terminate signal to the task + exit(0) // Exit the script after cleanup } - task?.launchPath = launchPath - task?.arguments = args + task.launchPath = launchPath + task.arguments = args if let env, - let combinedEnv = task?.environment?.merging(env, uniquingKeysWith: { (_, new) in new }) + let combinedEnv = task.environment?.merging(env, uniquingKeysWith: { (_, new) in new }) { - task?.environment = combinedEnv + task.environment = combinedEnv } if quiet { - task?.standardOutput = nil - task?.standardError = nil + task.standardOutput = nil + task.standardError = nil } - task?.launch() - task?.waitUntilExit() - return task?.terminationStatus ?? 1 + task.launch() + task.waitUntilExit() + return task.terminationStatus } func run(