mirror of
https://github.com/mas-cli/mas
synced 2024-11-22 11:33:13 +00:00
♻️ Simplify pointer dance
This commit is contained in:
parent
bea967ea80
commit
7f38f3537c
1 changed files with 4 additions and 11 deletions
|
@ -43,21 +43,14 @@ class MasAppLibrary: AppLibrary {
|
|||
printWarning("Apps installed from the Mac App Store require root permission to remove.")
|
||||
}
|
||||
|
||||
let fileManager = FileManager()
|
||||
let appUrl = URL(fileURLWithPath: app.bundlePath)
|
||||
|
||||
do {
|
||||
var trashUrl: NSURL?
|
||||
try withUnsafeMutablePointer(to: &trashUrl) { (mutablePointer: UnsafeMutablePointer<NSURL?>) in
|
||||
let pointer = AutoreleasingUnsafeMutablePointer<NSURL?>(mutablePointer)
|
||||
|
||||
// Move item to trash
|
||||
try fileManager.trashItem(at: appUrl, resultingItemURL: pointer)
|
||||
|
||||
if let url = pointer.pointee, let path = url.path {
|
||||
var trashUrl: NSURL?
|
||||
try FileManager().trashItem(at: appUrl, resultingItemURL: &trashUrl)
|
||||
if let path = trashUrl?.path {
|
||||
printInfo("App moved to trash: \(path)")
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
printError("Unable to move app to trash.")
|
||||
throw MASError.uninstallFailed
|
||||
|
|
Loading…
Reference in a new issue