mirror of
https://github.com/mas-cli/mas
synced 2024-11-22 03:23:08 +00:00
🔊 Add warning when uninstall command not run as root
This commit is contained in:
parent
1f84bf2340
commit
9d4fde5bb0
1 changed files with 11 additions and 0 deletions
|
@ -38,6 +38,10 @@ public class MasAppLibrary: AppLibrary {
|
|||
/// - Parameter app: App to be removed.
|
||||
/// - Throws: Error if there is a problem.
|
||||
public func uninstallApp(app: SoftwareProduct) throws {
|
||||
if !userIsRoot() {
|
||||
printWarning("Apps installed from the Mac App Store require root permission to remove.")
|
||||
}
|
||||
|
||||
let fileManager = FileManager()
|
||||
let appUrl = URL(fileURLWithPath: app.bundlePath)
|
||||
|
||||
|
@ -58,4 +62,11 @@ public class MasAppLibrary: AppLibrary {
|
|||
throw MASError.uninstallFailed
|
||||
}
|
||||
}
|
||||
|
||||
/// Detects whether the current user is root.
|
||||
///
|
||||
/// - Returns: true if the current user is root; false otherwise
|
||||
private func userIsRoot() -> Bool {
|
||||
return NSUserName() == "root"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue