🔊 Add warning when uninstall command not run as root

This commit is contained in:
Ben Chatelain 2019-01-20 22:14:11 -07:00
parent 1f84bf2340
commit 9d4fde5bb0

View file

@ -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"
}
}