Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Forget a receipt in the home folder without asking for the helper
Țugui Dragoșc98f31aa697d
diff --git a/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift b/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swiftindex 6d3c8e09..ebcd7bcb 100644--- a/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift+++ b/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift@@ -1,5 +1,4 @@public import Foundation-internal import PeelPrivilegedpublic enum PackageActions {static let misplacedReceipt = "The receipt isn’t where macOS keeps receipts."@@ -44,11 +43,20 @@ public enum PackageActions {/// The folder macOS keeps the receipts of `volume` in. For a package installed for one account, `pkgutil` names/// that account's home folder as the volume, and the receipt is in the Library there.private static func receiptsFolder(onVolume volume: URL, home: URL) -> URL {- let isTheHome = PathPattern.comparablePath(of: volume) == PathPattern.comparablePath(of: home)- let folder = isTheHome ? "Library/Receipts" : "private/var/db/receipts"+ let folder = isTheHome(volume, home: home) ? "Library/Receipts" : "private/var/db/receipts"return volume.appending(path: folder, directoryHint: .isDirectory)}+ /// Whether forgetting `receipt` takes Peel's helper: a disk's receipts are root's, and one in a home folder is that+ /// account's.+ public static func forgettingNeedsTheHelper(_ receipt: PackageReceipt, home: URL = .homeDirectory) -> Bool {+ !isTheHome(receipt.volume, home: home)+ }++ private static func isTheHome(_ volume: URL, home: URL) -> Bool {+ PathPattern.comparablePath(of: volume) == PathPattern.comparablePath(of: home)+ }+/// Moves the receipt to the Trash, so macOS stops counting the package as installed and History can put/// it back. `pkgutil --forget` would delete the same two files for good, and they are the only record of/// what the package installed. Files the package installed stay where they are.@@ -66,6 +74,7 @@ public enum PackageActions {static func forget(_ receipts: [PackageReceipt], through service: TrashService) async -> TrashResult {let home = service.environment.homeDirectoryvar files: [URL] = []+ var forTheHelper: [URL] = []var refused: [TrashFailure] = []for receipt in receipts {let own = receiptFiles(of: receipt.identifier, onVolume: receipt.volume, home: home)@@ -81,14 +90,10 @@ public enum PackageActions {refused.append(TrashFailure(url: missing, reason: .failed(why)))} else {files += own+ if forgettingNeedsTheHelper(receipt, home: home) { forTheHelper += own }}}guard !files.isEmpty else { return TrashResult(failures: refused) }- // The helper serves no folder of a home, and the account can move what is there itself.- let homeFolder = PathPattern.comparablePath(of: home)- let forTheHelper = files.filter {- !PathComponents.isPath(PathPattern.comparablePath(of: $0), inside: homeFolder)- }var result = await service.trash(files, usingHelperFor: Set(forTheHelper))result.failures += refusedreturn resultdiff --git a/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swiftindex a659ef6d..5a85943d 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swift@@ -118,6 +118,16 @@ struct PackageActionsTests {#expect(result.failures.isEmpty)}+ @Test func onlyAReceiptOutsideTheHomeFolderTakesTheHelperToForget() {+ let home = URL(filePath: "/Users/example", directoryHint: .isDirectory)++ #expect(PackageActions.forgettingNeedsTheHelper(receipt("org.example.solo", on: URL(filePath: "/")), home: home))+ #expect(!PackageActions.forgettingNeedsTheHelper(receipt("org.example.solo", on: home), home: home))+ #expect(PackageActions.forgettingNeedsTheHelper(+ receipt("org.example.solo", on: URL(filePath: "/Volumes/Other", directoryHint: .isDirectory)), home: home+ ))+ }+@Test func aReceiptInTheHomeFolderCountsAsAChange() throws {let directory = try TemporaryDirectory()let root = directory.url.appending(path: "root", directoryHint: .isDirectory)diff --git a/Peel/Views/Packages/PackageDetailView.swift b/Peel/Views/Packages/PackageDetailView.swiftindex 2d067c9a..8177e516 100644--- a/Peel/Views/Packages/PackageDetailView.swift+++ b/Peel/Views/Packages/PackageDetailView.swift@@ -53,11 +53,12 @@ struct PackageDetailView: View {.listRowSeparator(.hidden)}- // Forget Receipt always needs the helper, whatever the items need, unless the exclusions leave it alone.+ // Forget Receipt needs the helper for a disk's receipt, whatever the items need, unless the exclusions+ // leave it alone.if !helper.canAct {if receipt.itemsWaitingForTheHelper > 0 {HelperRequiredBanner(need: .moving(receipt.itemsWaitingForTheHelper))- } else if !isForAnExcludedApp {+ } else if forgettingWaitsForTheHelper, !isForAnExcludedApp {HelperRequiredBanner(need: .forgettingThisReceipt)}}@@ -119,7 +120,7 @@ struct PackageDetailView: View {Button("Forget Receipt") {receiptToForget = receipt}- .disabled(!helper.canAct || !history.mayMove || isForAnExcludedApp)+ .disabled(forgettingWaitsForTheHelper || !history.mayMove || isForAnExcludedApp).help(forgetHelp)}}@@ -172,13 +173,17 @@ struct PackageDetailView: View {receipt.apps.contains(where: ExclusionsStore.shared.exclusions.excludes)}+ private var forgettingWaitsForTheHelper: Bool {+ !helper.canAct && PackageActions.forgettingNeedsTheHelper(receipt)+ }+private var forgetHelp: Text {if isForAnExcludedApp {return Text("The app this package installed is excluded in Settings, so Peel leaves its receipt alone too.")}- return helper.canAct- ? Text("The receipt goes to the Trash. Files stay where they are.")- : Text(helper.standing.whyItCannotAct(registeredByAnotherCopy: helper.isRegisteredByAnotherCopy))+ return forgettingWaitsForTheHelper+ ? Text(helper.standing.whyItCannotAct(registeredByAnotherCopy: helper.isRegisteredByAnotherCopy))+ : Text("The receipt goes to the Trash. Files stay where they are.")}/// What an app that uninstalls itself once it moves does then, as its own page warns.diff --git a/Peel/Views/Packages/PackageList.swift b/Peel/Views/Packages/PackageList.swiftindex 9faa3af2..96885a0f 100644--- a/Peel/Views/Packages/PackageList.swift+++ b/Peel/Views/Packages/PackageList.swift@@ -34,8 +34,8 @@ struct PackageList: View {.minimumTarget()}.buttonStyle(.borderless)- .disabled(packages.isWorking || !helper.canAct || !history.mayMove)- .help(forgetAllHelp)+ .disabled(packages.isWorking || waitsForTheHelper(toForget: receiptsOnly) || !history.mayMove)+ .help(forgetAllHelp(for: receiptsOnly))}}}@@ -143,8 +143,12 @@ struct PackageList: View {.tag(receipt.id)}- private var forgetAllHelp: Text {- guard helper.canAct else {+ private func waitsForTheHelper(toForget receipts: [PackageReceipt]) -> Bool {+ !helper.canAct && receipts.contains { PackageActions.forgettingNeedsTheHelper($0) }+ }++ private func forgetAllHelp(for receipts: [PackageReceipt]) -> Text {+ guard !waitsForTheHelper(toForget: receipts) else {return Text(helper.standing.whyItCannotAct(registeredByAnotherCopy: helper.isRegisteredByAnotherCopy))}return Text(verbatim: history.holdingReason?.explanation ?? "")