Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Tell about an app thrown away even while Peel's list still names it

Țugui Dragoșc4e1337d71d5
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift
index f535b4dd..bd1ae2fe 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift
@@ -21,13 +21,14 @@ public enum AppInspector {
}
/// Whether a copy of the app at `url` other than that one is installed, outside a Trash: one of `installedApps`, or
- /// one macOS knows, with the same identifier. An app with no valid identifier has no copies to tell apart.
+ /// one macOS knows, with the same identifier, that is still there. The list may still name the place the app was
+ /// just moved from. An app with no valid identifier has no copies to tell apart.
public static func anotherCopyIsInstalled(of url: URL, among installedApps: [InstalledApp]) -> Bool {
guard let identifier = inspect(url)?.bundleIdentifier, Identifier.isValid(identifier) else { return false }
let own = PathPattern.comparablePath(of: url)
let copies = installedApps.filter { $0.bundleIdentifier?.lowercased() == identifier.lowercased() }.map(\.url)
+ applicationURLs(forBundleIdentifier: identifier)
- return copies.contains { !isInATrash($0) && PathPattern.comparablePath(of: $0) != own }
+ return copies.contains { !isInATrash($0) && PathPattern.comparablePath(of: $0) != own && $0.isThere }
}
static func isInATrash(_ url: URL) -> Bool {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
index f94fca12..082b372a 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
@@ -32,11 +32,16 @@ struct AppInspectorTests {
let alone = try bundle("home/.Trash/Alone.app", "org.example.inspector.alone")
let nameless = try bundle("home/.Trash/Nameless.app", nil)
let installed = [kept, trashed, nameless].compactMap(AppInspector.inspect)
+ let listedBeforeItMoved = try bundle("home/Applications/Moved.app", "org.example.inspector.moved")
+ let stillListed = [listedBeforeItMoved].compactMap(AppInspector.inspect)
+ let moved = directory.url.appending(path: "home/.Trash/Moved.app", directoryHint: .isDirectory)
+ try FileManager.default.moveItem(at: listedBeforeItMoved, to: moved)
#expect(AppInspector.anotherCopyIsInstalled(of: trashed, among: installed))
#expect(!AppInspector.anotherCopyIsInstalled(of: alone, among: installed))
#expect(!AppInspector.anotherCopyIsInstalled(of: nameless, among: installed))
#expect(!AppInspector.anotherCopyIsInstalled(of: trashed, among: [trashed].compactMap(AppInspector.inspect)))
+ #expect(!AppInspector.anotherCopyIsInstalled(of: moved, among: stillListed))
}
/// The shapes a binary comes in: thin (the usual shape of an Intel-only app), and fat with 20-byte or 32-byte