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.

Never offer a sibling product's uninstaller as an app's own

Țugui Dragoș86d89663802c
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/VendorRemoval.swift b/Packages/PeelCore/Sources/PeelCore/Removal/VendorRemoval.swift
index 2c52f411..b4fa3772 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/VendorRemoval.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/VendorRemoval.swift
@@ -20,7 +20,8 @@ public enum VendorRemoval {
}
let parent = app.url.deletingLastPathComponent()
// Inside the bundle, an uninstaller is the app's own even without the app's name. Beside the bundle it
- // must carry the app's name, because a vendor's folder holds its other products and their uninstallers.
+ // must be named for the app exactly, because a vendor's folder holds its other products and their
+ // uninstallers: Uninstall Acme Pro holds Acme's name and is not Acme's.
let isEveryMakers = isApplicationsFolder(parent) || applicationsFolders.contains {
PathPattern.comparablePath(of: $0) == PathPattern.comparablePath(of: parent)
}
@@ -28,8 +29,10 @@ public enum VendorRemoval {
for (folder, isInsideTheBundle) in folders {
let names = (try? fileManager.contentsOfDirectory(atPath: folder.path(percentEncoded: false))) ?? []
- if let match = names.sorted()
- .first(where: { isUninstallerName($0, app: app, isInsideTheBundle: isInsideTheBundle) }) {
+ let isTheAppsUninstaller = { (name: String) in
+ isInsideTheBundle ? isUninstallerName(name, app: app) : isUninstallerNamedExactly(name, for: app)
+ }
+ if let match = names.sorted().first(where: isTheAppsUninstaller) {
return folder.appending(path: match)
}
}
@@ -68,13 +71,13 @@ public enum VendorRemoval {
return app.names.contains { $0.lowercased() == named }
}
- static func isUninstallerName(_ name: String, app: InstalledApp, isInsideTheBundle: Bool = true) -> Bool {
+ static func isUninstallerName(_ name: String, app: InstalledApp) -> Bool {
guard name.hasSuffix(".app") else { return false }
let lowercased = name.lowercased()
guard lowercased.contains("uninstall") else { return false }
let base = lowercased.replacingOccurrences(of: ".app", with: "")
guard !app.names.contains(where: { base.contains($0.lowercased()) }) else { return true }
- return isInsideTheBundle && (base.hasPrefix("uninstall") || base.hasSuffix("uninstaller"))
+ return base.hasPrefix("uninstall") || base.hasSuffix("uninstaller")
}
/// Whether `url` is an Applications folder. A folder URL's path ends in a slash, so the path is read through
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TranslatedNameTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/TranslatedNameTests.swift
index 18d50c21..88090556 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/TranslatedNameTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/TranslatedNameTests.swift
@@ -26,6 +26,6 @@ import Testing
}
@Test func theUninstallerBesideItIsStillItsOwn() {
- #expect(VendorRemoval.isUninstallerName("Uninstall Latest.app", app: latest, isInsideTheBundle: false))
+ #expect(VendorRemoval.isUninstallerNamedExactly("Uninstall Latest.app", for: latest))
}
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/VendorRemovalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/VendorRemovalTests.swift
index a407265b..6e07ee59 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/VendorRemovalTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/VendorRemovalTests.swift
@@ -61,6 +61,19 @@ struct VendorRemovalTests {
#expect(VendorRemoval.uninstaller(for: app(in: directory, path: "Suite/Example.app", name: "Example")) == nil, "a vendor's folder holds its other products too")
}
+ @Test func aSiblingProductsUninstallerIsNotThisAppsEvenWhenItsNameHoldsThisOne() throws {
+ let directory = try TemporaryDirectory()
+ try directory.directory("Acme/Acme.app")
+ try directory.directory("Acme/Acme Pro.app")
+ try directory.directory("Acme/Uninstall Acme Pro.app")
+
+ #expect(VendorRemoval.uninstaller(for: app(in: directory, path: "Acme/Acme.app", name: "Acme")) == nil)
+ #expect(
+ VendorRemoval.uninstaller(for: app(in: directory, path: "Acme/Acme Pro.app", name: "Acme Pro"))?
+ .lastPathComponent == "Uninstall Acme Pro.app"
+ )
+ }
+
/// In Homebrew's casks, an uninstaller app sits inside the bundle, beside it, at the top of `/Applications`
/// (Chrome Remote Desktop Host Uninstaller), or in a maker's folder in Utilities (Adobe Installers). The
/// last two hold every maker's uninstallers, so there the name must be the app's own name with only