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.

Keep an app's receipt while its package left more outside it

Țugui Dragoș7437f903291d
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index 946fd6ea..a20f37b9 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -73,7 +73,8 @@ the Homebrew page's uninstall and cleanups are Homebrew's own.
top of the home folder, and more. It adds the paths the app's Homebrew cask names in its `uninstall` and `zap`
stanzas, whether or not Homebrew installed the app (`CaskEvidence`); the installer receipt that proves the app,
its two files in `/private/var/db/receipts`, while what the package installed stays with the Package Receipts
- page; the cask's own folder in Homebrew's Caskroom when Homebrew installed it (`HomebrewPackage.caskroomFolder`);
+ page, which lists it only while the receipt is there, so a receipt whose package left more outside the app is
+ held back; the cask's own folder in Homebrew's Caskroom when Homebrew installed it (`HomebrewPackage.caskroomFolder`);
and what an area the app manages keeps in the home folder, such as Xcode's simulators. A page's scan runs
through its `ScanRun`, so a newer scan or the Stop button ends an older one, and it counts what it reads so the
page can show progress.
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index a48432c3..b4ce8b8d 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -102257,6 +102257,113 @@
}
}
},
+ "Not selected: the package also left items outside the app. Package Receipts lists them only while this receipt is here." : {
+ "comment" : "Under an installer receipt in the list of what an uninstall would move. Package Receipts is the name of a page in Peel's sidebar.",
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nevybráno: balíček zanechal položky i mimo aplikaci. Stránka Záznamy o instalaci je uvádí, jen dokud tu tento záznam je."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nicht ausgewählt: Das Paket hat auch Objekte außerhalb der App hinterlassen. Die Seite „Paketquittungen“ führt sie nur auf, solange diese Quittung vorhanden ist."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Sin seleccionar: el paquete también dejó ítems fuera de la app. La página Recibos de paquetes solo los muestra mientras este recibo siga aquí."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non sélectionné : le paquet a aussi laissé des éléments hors de l’app. La page Reçus de paquets ne les liste que tant que ce reçu est présent."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non selezionato: il pacchetto ha lasciato elementi anche fuori dall’app. “Ricevute dei pacchetti” li elenca solo finché questa ricevuta è qui."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未選択: このパッケージは、アプリの外にも項目を残しています。“パッケージレシート”にそれらが表示されるのは、このレシートがここにある間だけです。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "선택되지 않음: 이 패키지는 앱 밖에도 항목을 남겼습니다. 패키지 수신 정보 페이지는 이 수신 정보가 있는 동안에만 해당 항목을 나열합니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Niet geselecteerd: het pakket heeft ook onderdelen buiten de app achtergelaten. De pagina 'Installatiebewijzen' toont ze alleen zolang dit installatiebewijs er is."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie zaznaczono: pakiet pozostawił też rzeczy poza aplikacją. Strona Potwierdzenia instalacji wyświetla je tylko wtedy, gdy to potwierdzenie pozostaje na miejscu."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Não selecionado: o pacote também deixou itens fora do app. A página Recibos de Pacotes só os lista enquanto este recibo estiver aqui."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Neselectat: pachetul a lăsat articole și în afara aplicației. Pagina Recipise de pachete le listează doar cât timp această recipisă se află aici."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не выбрано: пакет также оставил объекты вне приложения. Раздел «Квитанции пакетов» показывает их, только пока эта квитанция на месте."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Inte markerad: paketet har även lämnat objekt utanför appen. Sidan Paketkvitton listar dem bara så länge det här kvittot finns kvar."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Seçilmedi: paket, uygulamanın dışında da öğeler bıraktı. Paket Makbuzları bunları yalnızca bu makbuz burada olduğu sürece listeler."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не вибрано: пакет також залишив елементи поза програмою. Розділ «Квитанції пакетів» показує їх, лише поки ця квитанція на місці."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未选择:该软件包还在App之外留下了项目。只有此回执还在时,“软件包回执”才会列出它们。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未選取:此套件也在App以外留下了項目。只有在此收據還在時,「套件收據」才會列出它們。"
+ }
+ }
+ }
+ },
"Not selected: the package made this folder, but something else put files in it, which may be another program’s or yours." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index b36565b3..cf2d7ff8 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -372,6 +372,7 @@ extension HoldBack {
case .holdsVPNConnections: "holds VPN connections that may exist only on this Mac"
case .holdsSignIns: "holds a sign-in to a service, such as a token a tool saved when you logged in"
case .holdsTorrents: "holds your list of torrents and how far each one got, which may exist only on this Mac"
+ case .packageLeftMore: "its package also left items outside the app, which Package Receipts lists only while it stays"
case .holdsWorkMadeWithTheApp:
"holds what you made with the app, such as saved games, databases, or its backups, that may exist only here"
case .holdsSimulators: "holds the app's simulators, with the apps installed in them and their data"
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
index b19e2315..9037713e 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
@@ -145,6 +145,8 @@ public enum HoldBack: String, Sendable, Hashable {
case writtenRecently
/// An installer package in a folder an app keeps in Application Support, which the app may still need.
case keptByAnApp
+ /// A receipt whose package also left items outside the app, which Package Receipts lists only while it stays.
+ case packageLeftMore
/// An update whose app is running, which may install it when it quits.
case appIsRunning
/// An installer outside Downloads that is no installed app's, which may be the person's own rather than a download.
diff --git a/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipts.swift b/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipts.swift
index 8d3be9bc..f61ce0a4 100644
--- a/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipts.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipts.swift
@@ -190,6 +190,17 @@ public enum PackageReceipts {
return found
}
+ /// Whether the package left anything outside `app` that is still on the disk, of which the receipt is the only
+ /// record. A package `pkgutil` doesn't describe counts as having left something, so its receipt stays.
+ static func leftSomethingOutside(_ identifier: String, app: URL, pkgutil: Pkgutil) async -> Bool {
+ guard let (_, _, installLocation) = await description(of: identifier, pkgutil: pkgutil),
+ let listing = await pkgutil(["--files", identifier])
+ else { return true }
+ let bundle = PathPattern.comparablePath(of: PathPattern.canonical(app))
+ return topLevel(files: lines(of: listing), installLocation: installLocation.path(percentEncoded: false)).onDisk
+ .contains { !PathComponents.isPath(PathPattern.comparablePath(of: URL(filePath: $0)), atOrInside: bundle) }
+ }
+
/// The packages whose receipts list the bundle at `path`, as `pkgutil` names them: it matches a path literally
/// against each receipt's file list, which is relative to the package's install location.
private static func packages(listing path: String, pkgutil: Pkgutil) async -> Set<String> {
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
index 4f6aeb17..6c09445c 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
@@ -141,7 +141,8 @@ public struct Uninstallation: Sendable {
/// The installer receipt files that belong to `app`. The receipt is the only reason macOS still counts the
/// package as installed once the app is gone, and it is two small files the Trash can give back. What the
- /// package installed elsewhere is left to the Package Receipts page, which weighs each item on its own.
+ /// package installed elsewhere is left to the Package Receipts page, which weighs each item on its own and lists
+ /// it only while the receipt is there, so a receipt whose package left more outside the app is held back.
static func receiptLeftovers(
for app: InstalledApp,
receipts: Set<String>,
@@ -159,16 +160,20 @@ public struct Uninstallation: Sendable {
.filter { !named.contains($0.lowercased()) }
var leftovers: [Leftover] = []
for receipt in (Array(named) + wroteOnlyTheApp).sorted() {
+ let leftMore = named.contains(receipt)
+ ? await PackageReceipts.leftSomethingOutside(receipt, app: app.url, pkgutil: pkgutil) : false
for url in PackageActions.receiptFiles(of: receipt, onVolume: environment.rootDirectory)
where !exclusions.excludes(url) {
- leftovers.append(await LeftoverScanner.leftover(
+ let leftover = await LeftoverScanner.leftover(
at: url,
kind: .receipts,
match: LeftoverMatch(reason: .installerReceipt, confidence: .certain, sharedWith: []),
parent: ParentAccess(url.deletingLastPathComponent()),
home: environment.homeDirectory.path(percentEncoded: false),
root: environment.rootDirectory.path(percentEncoded: false)
- ))
+ )
+ let heldForThePackage = leftMore && leftover.match.heldBack == nil
+ leftovers.append(heldForThePackage ? leftover.heldBack(.packageLeftMore) : leftover)
}
}
return leftovers
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
index c0b75d4e..a0c4ee14 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
@@ -1122,13 +1122,21 @@ struct UninstallationTests {
try directory.file("root/private/var/db/receipts/\(name).bom", bytes: 32)
try directory.file("root/private/var/db/receipts/\(name).plist", bytes: 32)
}
+ let pkgutil: PackageReceipts.Pkgutil = { arguments in
+ switch arguments.first {
+ case "--pkg-info-plist": PkgutilAnswer.packageInfo(arguments[1], location: "/")
+ case "--files": "Applications/Example.app\nApplications/Example.app/Contents\n"
+ default: nil
+ }
+ }
let found = await Uninstallation.receiptLeftovers(
for: app,
receipts: ["com.example.app.pkg", "com.example.app2.pkg", "com.other.thing"],
installedApps: [app],
exclusions: .none,
- environment: environment
+ environment: environment,
+ pkgutil: pkgutil
)
#expect(found.map(\.url.lastPathComponent) == ["com.example.app.pkg.bom", "com.example.app.pkg.plist"])
@@ -1138,6 +1146,39 @@ struct UninstallationTests {
#expect(found.map(\.kind) == [.receipts, .receipts])
}
+ @Test func keepsAReceiptWhosePackageLeftMoreOutsideTheApp() async throws {
+ let directory = try TemporaryDirectory()
+ let environment = SearchEnvironment(
+ homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),
+ rootDirectory: directory.url.appending(path: "root", directoryHint: .isDirectory)
+ )
+ let bundle = try directory.directory("root/Applications/Example.app")
+ try directory.file("root/Library/LaunchDaemons/com.example.helper.plist", bytes: 32)
+ try directory.file("root/private/var/db/receipts/com.example.app.pkg.bom", bytes: 32)
+ let example = InstalledApp(url: bundle, bundleIdentifier: "com.example.app", name: "Example")
+ let root = String(PathPattern.comparablePath(of: PathPattern.canonical(environment.rootDirectory)).dropFirst())
+ let asking = { (daemon: Bool) -> PackageReceipts.Pkgutil in
+ { arguments in
+ switch arguments.first {
+ case "--pkg-info-plist": PkgutilAnswer.packageInfo(arguments[1], location: root)
+ case "--files":
+ "Applications/Example.app\nApplications/Example.app/Contents\n"
+ + (daemon ? "Library/LaunchDaemons/com.example.helper.plist\n" : "")
+ default: nil
+ }
+ }
+ }
+ let found = { (daemon: Bool) in
+ await Uninstallation.receiptLeftovers(
+ for: example, receipts: ["com.example.app.pkg"], installedApps: [example], exclusions: .none,
+ environment: environment, pkgutil: asking(daemon)
+ )
+ }
+
+ #expect(await found(true).map(\.match.heldBack) == [.packageLeftMore])
+ #expect(await found(false).map(\.match.heldBack) == [nil])
+ }
+
/// A receipt whose name begins with this app's identifier can still be another installed app's, one whose
/// identifier carries on past the separator: `org.example.synth-fx.app.pkg` installed Synth FX, not Synth.
@Test func leavesAReceiptToTheAppItNamesMoreClosely() async throws {
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index f62707e0..8f29286d 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -370,6 +370,8 @@ extension HoldBack {
"Not selected: this holds a sign-in to a service, such as a token a tool saved when you logged in. Once the Trash is emptied, you’d sign in again."
case .holdsTorrents:
"Not selected: this holds your list of torrents and how far each one got, which may exist only on this Mac. Once the Trash is emptied, you’d have to add each torrent again."
+ case .packageLeftMore:
+ "Not selected: the package also left items outside the app. Package Receipts lists them only while this receipt is here."
case .holdsWorkMadeWithTheApp:
"Not selected: this holds what you made with the app, such as saved games, databases, or the app’s own backups, which may exist only on this Mac. Once the Trash is emptied, it’s gone for good unless you have another copy."
case .holdsSimulators: