mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-11-07 21:20:07 +01:00
👌 Ensure removal occurs after permissions fix
This commit is contained in:
@@ -72,22 +72,27 @@ public class PhpVersionInstaller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if action == .purge || action == .remove {
|
if action == .purge || action == .remove {
|
||||||
|
// Removal always requires permission
|
||||||
|
do {
|
||||||
|
try await PhpVersionInstaller.fixPermissions(for: formula)
|
||||||
|
} catch {
|
||||||
|
Task { @MainActor in
|
||||||
|
subject.progress = 1
|
||||||
|
subject.title = "Could not take permission of required folder"
|
||||||
|
subject.description = "Please try again!"
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actually do the removal
|
||||||
command = "brew remove \(formula) --force --ignore-dependencies"
|
command = "brew remove \(formula) --force --ignore-dependencies"
|
||||||
|
|
||||||
|
// Check if the permissions are correct; if not, fix permissions
|
||||||
if action == .purge {
|
if action == .purge {
|
||||||
command += " --zap"
|
command += " --zap"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: If this process fails, ensure that PHP Monitor can remove manually
|
|
||||||
//
|
|
||||||
// We can check for something like this:
|
|
||||||
//
|
|
||||||
// Error: Could not remove php@7.4 keg! Do so manually:
|
|
||||||
// sudo rm -rf /opt/homebrew/Cellar/php@7.4/7.4.33_1
|
|
||||||
//
|
|
||||||
// To invoke the manual removal
|
|
||||||
|
|
||||||
let (process, _) = try! await Shell.attach(
|
let (process, _) = try! await Shell.attach(
|
||||||
command,
|
command,
|
||||||
didReceiveOutput: { text, _ in
|
didReceiveOutput: { text, _ in
|
||||||
@@ -119,7 +124,9 @@ public class PhpVersionInstaller {
|
|||||||
} else {
|
} else {
|
||||||
// Do not close the window and notify about failure
|
// Do not close the window and notify about failure
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
subject.description = "The operation failed."
|
subject.title = "Operation failed."
|
||||||
|
subject.progress = 1
|
||||||
|
subject.description = "Something went wrong."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -127,6 +134,26 @@ public class PhpVersionInstaller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static func fixPermissions(for formula: String) async throws {
|
||||||
|
// Omit the prefix
|
||||||
|
let path = formula.replacingOccurrences(of: "shivammathur/php/", with: "")
|
||||||
|
|
||||||
|
let script = """
|
||||||
|
\(Paths.brew) services stop \(formula) \
|
||||||
|
&& chown -R \(Paths.whoami):admin \(Paths.cellarPath)/\(path)
|
||||||
|
"""
|
||||||
|
|
||||||
|
let appleScript = NSAppleScript(source:
|
||||||
|
"do shell script \"\(script)\" with administrator privileges"
|
||||||
|
)
|
||||||
|
|
||||||
|
let eventResult: NSAppleEventDescriptor? = appleScript?.executeAndReturnError(nil)
|
||||||
|
|
||||||
|
if eventResult == nil {
|
||||||
|
throw HomebrewPermissionError(kind: .applescriptNilError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static func installPhpVersion(version: String) async {
|
public static func installPhpVersion(version: String) async {
|
||||||
await self.modifyPhpVersion(version: version, action: .install)
|
await self.modifyPhpVersion(version: version, action: .install)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user