mirror of
https://github.com/mas-cli/mas
synced 2025-02-16 20:48:30 +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.")
|
printWarning("Apps installed from the Mac App Store require root permission to remove.")
|
||||||
}
|
}
|
||||||
|
|
||||||
let fileManager = FileManager()
|
|
||||||
let appUrl = URL(fileURLWithPath: app.bundlePath)
|
let appUrl = URL(fileURLWithPath: app.bundlePath)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
var trashUrl: NSURL?
|
|
||||||
try withUnsafeMutablePointer(to: &trashUrl) { (mutablePointer: UnsafeMutablePointer<NSURL?>) in
|
|
||||||
let pointer = AutoreleasingUnsafeMutablePointer<NSURL?>(mutablePointer)
|
|
||||||
|
|
||||||
// Move item to trash
|
// Move item to trash
|
||||||
try fileManager.trashItem(at: appUrl, resultingItemURL: pointer)
|
var trashUrl: NSURL?
|
||||||
|
try FileManager().trashItem(at: appUrl, resultingItemURL: &trashUrl)
|
||||||
if let url = pointer.pointee, let path = url.path {
|
if let path = trashUrl?.path {
|
||||||
printInfo("App moved to trash: \(path)")
|
printInfo("App moved to trash: \(path)")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
printError("Unable to move app to trash.")
|
printError("Unable to move app to trash.")
|
||||||
throw MASError.uninstallFailed
|
throw MASError.uninstallFailed
|
||||||
|
|
Loading…
Add table
Reference in a new issue