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.

Apply an app's removal rules to the rest of its package

Țugui Dragoș824dd2e3f6ea
diff --git a/GUIDE.md b/GUIDE.md
index 291a56ba..5a20d48f 100644
--- a/GUIDE.md
+++ b/GUIDE.md
@@ -229,11 +229,12 @@ and how many items the others hold.
the place in System Settings that turns it on or off.
- **Plug-ins:** plug-ins of every kind, from audio units to Quick Look, each of which you can move to the Trash,
after Peel warns that apps using it may stop working.
-- **Package Receipts:** what installer packages other than Apple's put on your Mac, item by item, to move to the
- Trash. Nothing is selected for you, and Select Recommended passes by a folder a package made that now holds what
- something else put there. Forget Receipt moves the receipt itself to the Trash, through Peel's helper, so macOS no
- longer counts the package as installed. An app a package installed follows the rules of its own page: one whose
- system extension macOS installed is left for you to move in Finder.
+- **Package Receipts:** what installer packages other than Apple's put on your Mac, item by item, to move to the Trash.
+ Nothing is selected for you, and Select Recommended passes by a folder a package made that now holds what something
+ else put there. Forget Receipt moves the receipt itself to the Trash, through Peel's helper, so macOS no longer counts
+ the package as installed. An app a package installed follows the rules of its own page, and so does the rest of its
+ package: what is left to Finder or to the maker's uninstaller stays where it is, and what may exist only on this Mac
+ is shown and not selected.
- **Intel Software:** what still needs Rosetta, which macOS 27 is the last release to offer for most Intel software:
apps, the Intel-only parts inside other apps, plug-ins, drivers, background items, and the commands in
`/usr/local`.
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/KeptOnlyHere.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/KeptOnlyHere.swift
index 8b23b149..77baf82e 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/KeptOnlyHere.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/KeptOnlyHere.swift
@@ -137,7 +137,7 @@ enum KeptOnlyHere {
]
static func reason(for path: String, home: String, root: String) -> HoldBack? {
- let item = PathComponents.of(path.lowercased())
+ let item = PathComponents.of((path as NSString).standardizingPath.lowercased())
for (base, list) in [(home, places), (root, localPlaces)] {
let base = (base as NSString).standardizingPath
for (folder, inside, reason) in list {
diff --git a/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipts.swift b/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipts.swift
index 52223d25..8bd0f70c 100644
--- a/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipts.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipts.swift
@@ -91,7 +91,8 @@ public enum PackageReceipts {
removalGuard: removalGuard,
reach: reach,
shared: shared,
- installed: installed
+ installed: installed,
+ environment: environment
).receipt
}
}
@@ -106,7 +107,8 @@ public enum PackageReceipts {
removalGuard: removalGuard,
reach: reach,
shared: shared,
- installed: installed
+ installed: installed,
+ environment: environment
).receipt
}
}
@@ -155,7 +157,8 @@ public enum PackageReceipts {
removalGuard: removalGuard,
reach: reach,
shared: shared,
- installed: installed
+ installed: installed,
+ environment: .current
)
guard found.installs(wanted) else { continue }
receipts.append(found.receipt)
@@ -246,7 +249,8 @@ public enum PackageReceipts {
removalGuard: RemovalGuard,
reach: HelperReach,
shared: [String],
- installed: InstalledSystemExtensions
+ installed: InstalledSystemExtensions,
+ environment: SearchEnvironment
) async -> Found {
guard let (info, volume, installLocation) = await description(of: identifier, pkgutil: pkgutil) else {
// `pkgutil` named the package but did not describe it. It stays listed, with what it installed unknown,
@@ -265,6 +269,18 @@ public enum PackageReceipts {
let files = lines(of: listing)
let found = topLevel(files: files, installLocation: installLocation.path(percentEncoded: false))
+ // An app's own rules reach the rest of its package, as they reach its files on its page.
+ let apps = found.offered
+ .filter { ($0 as NSString).pathExtension.caseInsensitiveCompare("app") == .orderedSame }
+ .compactMap { AppInspector.inspect(URL(filePath: PathPattern.located($0) ?? $0)) }
+ var removedApps: [String: RemovedElsewhere] = [:]
+ for app in apps {
+ let carried = await AppExtensions.installed(carriedBy: app) { await installed.answer() }
+ let removed = RemovedElsewhere.of(app, installedSystemExtensions: carried)
+ removedApps[PathPattern.comparablePath(of: app.url)] = removed
+ }
+ let removedWithItsApp = apps.lazy.compactMap { removedApps[PathPattern.comparablePath(of: $0.url)] }.first
+ let uninstaller = apps.lazy.compactMap { UninstallsItself.of($0, environment: environment) }.first
var items: [PackageReceipt.Item] = []
var seen: Set<String> = []
for path in found.offered {
@@ -277,18 +293,27 @@ public enum PackageReceipts {
let place = PathPattern.comparablePath(of: url)
let isShared = shared.contains { PathComponents.isPath(place, atOrInside: $0) }
let isFilledByOthers = found.othersFilled.contains(path)
+ let heldBack: HoldBack? = if SignInPlugIns.isOne(url, root: volume) {
+ .signInPlugIn
+ } else if requiresPrivileges && reach.isBeyond(url) {
+ .beyondTheHelper
+ } else if uninstaller?.removes(url) == true {
+ .leftToItsUninstaller
+ } else {
+ KeptOnlyHere.reason(
+ for: url.path(percentEncoded: false), home: environment.homeDirectory.path(percentEncoded: false),
+ root: volume.path(percentEncoded: false)
+ ) ?? HoldBack.seen(in: contents) ?? contents.flatMap(KeptOnlyHere.reason(seenIn:))
+ ?? (isShared ? .sharedWithEveryone : nil) ?? (isFilledByOthers ? .holdsWhatOthersPut : nil)
+ }
items.append(PackageReceipt.Item(
url: url,
size: contents.flatMap { $0.couldNotBeRead ? nil : $0.size },
requiresPrivileges: requiresPrivileges,
refusal: removalGuard.refusal(of: url),
- heldBack: SignInPlugIns.isOne(url, root: volume)
- ? .signInPlugIn
- : requiresPrivileges && reach.isBeyond(url)
- ? .beyondTheHelper
- : HoldBack.seen(in: contents) ?? (isShared ? .sharedWithEveryone : nil)
- ?? (isFilledByOthers ? .holdsWhatOthersPut : nil),
- removedElsewhere: await removedElsewhere(url, installed: installed)
+ heldBack: heldBack,
+ removedElsewhere: url.pathExtension.caseInsensitiveCompare("app") == .orderedSame
+ ? removedApps[place] : removedWithItsApp
))
}
@@ -307,15 +332,6 @@ public enum PackageReceipts {
)
}
- /// How an app a package installed is removed instead, by the rules its own page follows: Finder for its system
- /// extensions, Remove Peel for Peel, its maker's uninstaller for an agent.
- private static func removedElsewhere(_ url: URL, installed: InstalledSystemExtensions) async -> RemovedElsewhere? {
- guard url.pathExtension.caseInsensitiveCompare("app") == .orderedSame, let app = AppInspector.inspect(url)
- else { return nil }
- let carried = await AppExtensions.installed(carriedBy: app) { await installed.answer() }
- return RemovedElsewhere.of(app, installedSystemExtensions: carried)
- }
-
/// What `pkgutil --pkg-info-plist` says of a package, with the volume and the folder its file list is relative to.
private static func description(
of identifier: String,
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift
index e1342fdf..6c97bbe5 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift
@@ -260,6 +260,88 @@ struct PackageReceiptsTests {
#expect(items["Plain.app"]?.isLeftAlone == false)
}
+ @Test func leavesTheRestOfAPackageToWhatRemovesItsApp() async throws {
+ let directory = try TemporaryDirectory()
+ let volume = PathPattern.canonical(directory.url)
+ let plist = { (object: [String: Any]) in
+ try PropertyListSerialization.data(fromPropertyList: object, format: .xml, options: 0)
+ }
+ try directory.file(
+ "Applications/Guard.app/Contents/Info.plist",
+ contents: plist(["CFBundleIdentifier": "org.example.guard", "CFBundleName": "Guard"])
+ )
+ try directory.file(
+ "Applications/Guard.app/Contents/Library/SystemExtensions/org.example.guard.filter.systemextension/Contents/Info.plist",
+ contents: plist(["CFBundleIdentifier": "org.example.guard.filter", "CFBundleName": "Guard Filter"])
+ )
+ try directory.file("Library/Application Support/Guard/rules.json", bytes: 16)
+ let workspace = "Applications/Citrix Workspace.app"
+ try directory.file(
+ "\(workspace)/Contents/Info.plist",
+ contents: plist(["CFBundleIdentifier": "com.citrix.receiver.nomas", "CFBundleName": "Citrix Workspace"])
+ )
+ let uninstaller = "Library/Citrix Workspace/Uninstaller/Uninstall Citrix Workspace"
+ try directory.file(uninstaller)
+ try directory.setPermissions(0o755, of: uninstaller)
+ try directory.file("Library/LaunchAgents/com.citrix.UninstallMonitor.plist", contents: plist([
+ "Label": "com.citrix.UninstallMonitor",
+ "ProgramArguments": [volume.appending(path: uninstaller).path(percentEncoded: false)],
+ "WatchPaths": [volume.appending(path: workspace).path(percentEncoded: false)],
+ ]))
+ try directory.file("Library/Application Support/Citrix Receiver/config.xml", bytes: 16)
+ try directory.file("Library/Application Support/Citrix Extra/notes.txt", bytes: 16)
+ try directory.file("Library/Application Support/ZeroTier/One/zerotier-one", bytes: 16)
+ try directory.file("Library/Application Support/ZeroTier/One/identity.secret", bytes: 16)
+ let files = [
+ "org.example.guard.pkg": [
+ "Applications/Guard.app", "Library/Application Support/Guard",
+ "Library/Application Support/Guard/rules.json",
+ ],
+ "com.citrix.ICAClient": [
+ workspace, "Library/Application Support/Citrix Receiver",
+ "Library/Application Support/Citrix Receiver/config.xml", "Library/Application Support/Citrix Extra",
+ "Library/Application Support/Citrix Extra/notes.txt",
+ ],
+ "com.zerotier.pkg.ZeroTierOne": [
+ "Library/Application Support/ZeroTier", "Library/Application Support/ZeroTier/One",
+ "Library/Application Support/ZeroTier/One/zerotier-one",
+ ],
+ ]
+ let pkgutil: PackageReceipts.Pkgutil = { arguments in
+ switch arguments.first {
+ case "--pkgs-plist":
+ return PkgutilAnswer.packages("com.citrix.ICAClient", "com.zerotier.pkg.ZeroTierOne", "org.example.guard.pkg")
+ case "--pkg-info-plist":
+ let info = ["volume": volume.path(percentEncoded: false), "install-location": "/"]
+ let data = try? PropertyListSerialization.data(fromPropertyList: info, format: .xml, options: 0)
+ return data.flatMap { String(data: $0, encoding: .utf8) }
+ case "--files":
+ return files[arguments[1]]?.joined(separator: "\n")
+ default:
+ return nil
+ }
+ }
+ let filter = AppExtension(
+ identifier: "org.example.guard.filter", name: "Guard Filter", kind: .systemExtension, point: nil, owner: nil,
+ url: nil, election: .on, teamIdentifier: nil, reportedState: nil
+ )
+ let environment = SearchEnvironment(homeDirectory: volume.appending(path: "home"), rootDirectory: volume)
+
+ let scan = await PackageReceipts.list(
+ exclusions: .none, pkgutil: pkgutil, environment: environment, systemExtensions: { [filter] }
+ )
+
+ let items = Dictionary(
+ uniqueKeysWithValues: scan.receipts.flatMap(\.items).map { ($0.url.lastPathComponent, $0) }
+ )
+ let finder = RemovedElsewhere.byFinder(systemExtensions: CarriedSystemExtensions(names: ["Guard Filter"]))
+ #expect(items["Guard"]?.removedElsewhere == finder)
+ #expect(items["Guard"]?.isLeftAlone == true)
+ #expect(items["Citrix Receiver"]?.heldBack == .leftToItsUninstaller)
+ #expect(items["Citrix Extra"]?.heldBack == nil)
+ #expect(items["zerotier-one"]?.heldBack == .holdsVPNConnections)
+ }
+
/// A receipt's file list leaves out the install prefix, such as `Applications`, so the path is asked about again
/// without its leading folders, and the answer is believed only if the receipt really installed that path.
@Test func findsThePackageThatInstalledAnAppUnderAnInstallPrefix() async throws {