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.

Say a receipt was already forgotten, not that it is misplaced

Țugui Dragoș790be1c1bf5d
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 22ca001b..adb842f0 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -66777,6 +66777,112 @@
}
}
},
+ "It was already forgotten." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Záznam už byl zapomenut."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Die Quittung wurde bereits vergessen."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ya se había olvidado."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Il avait déjà été oublié."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Era già stata dimenticata."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "このレシートはすでにゴミ箱に入れられました。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "수신 정보가 이미 제거되었습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Het was al vergeten."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "To potwierdzenie zostało już zapomniane."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ele já tinha sido esquecido."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Recipisa a fost deja uitată."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Квитанция уже забыта."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Det var redan glömt."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zaten unutulmuştu."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Її вже забуто."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "该回执已被移除。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "此收據已經被移除。"
+ }
+ }
+ }
+ },
"It was first seen signed by %@, and is signed by %@ now." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift b/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift
index 7f887c83..350265e7 100644
--- a/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift
@@ -2,6 +2,7 @@ public import Foundation
public enum PackageActions {
static let misplacedReceipt = "The receipt isn’t where macOS keeps receipts."
+ static let forgottenReceipt = "It was already forgotten."
/// Returns the receipt's files that exist: `<identifier>.bom` and `<identifier>.plist` in
/// `private/var/db/receipts` on `volume`. macOS counts the package as installed only while they are there.
@@ -47,9 +48,12 @@ public enum PackageActions {
static func forget(_ receipt: PackageReceipt, through service: TrashService) async -> TrashResult {
let files = receiptFiles(of: receipt.identifier, onVolume: receipt.volume)
guard !files.isEmpty else {
- // Named by the file macOS would keep, so the failure says which receipt rather than which disk.
- let missing = receiptsFolder(onVolume: receipt.volume).appending(path: receipt.identifier + ".plist")
- return TrashResult(failures: [TrashFailure(url: missing, reason: .failed(Self.misplacedReceipt))])
+ // Named by the file macOS would keep, so the failure says which receipt rather than which disk. With the
+ // folder there, the receipt was forgotten some other way since Peel read it.
+ let folder = receiptsFolder(onVolume: receipt.volume)
+ let missing = folder.appending(path: receipt.identifier + ".plist")
+ let why = folder.isRealFolder ? Self.forgottenReceipt : Self.misplacedReceipt
+ return TrashResult(failures: [TrashFailure(url: missing, reason: .failed(why))])
}
return await service.trash(files, usingHelperFor: Set(files))
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/FixedSentence.swift b/Packages/PeelCore/Sources/PeelCore/Support/FixedSentence.swift
index 39ad9843..a5c510fe 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/FixedSentence.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/FixedSentence.swift
@@ -1,7 +1,7 @@
internal import PeelPrivileged
/// Every fixed English sentence Peel's own code shows the user from outside the app's string catalog: the
-/// refusals of the path rules and of the helper, a tool that timed out or was stopped, and three of PeelCore's.
+/// refusals of the path rules and of the helper, a tool that timed out or was stopped, and four of PeelCore's.
/// The helper cannot know the user's language and PeelCore has no catalog, so each arrives in English, and
/// the app recognizes it here to show it translated. Anything else (a tool's own output, an error macOS
/// wrote) is not one of these.
@@ -13,7 +13,7 @@ public enum FixedSentence: CaseIterable, Sendable {
case helperOutOfDate, accountNotAllowed, tooManyItems, noTrash, pathTooLong, cannotKeepRecord, cannotReadRecord
case notInTrash, notMovedByHelper, invalidRequest, configurationMissing
case toolTimedOut, toolStopped
- case receiptMisplaced, homebrewNotInstalled, helperUnavailable
+ case receiptMisplaced, receiptForgotten, homebrewNotInstalled, helperUnavailable
public init?(_ message: String) {
guard let found = Self.allCases.first(where: { $0.english == message }) else { return nil }
@@ -52,6 +52,7 @@ public enum FixedSentence: CaseIterable, Sendable {
case .toolTimedOut: Subprocess.Failure.timedOut.explanation
case .toolStopped: Subprocess.Failure.canceled.explanation
case .receiptMisplaced: PackageActions.misplacedReceipt
+ case .receiptForgotten: PackageActions.forgottenReceipt
case .homebrewNotInstalled: Homebrew.notInstalled
case .helperUnavailable: PrivilegedHelper.unavailable
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swift
index 07f372df..71f861c3 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swift
@@ -108,5 +108,10 @@ struct PackageActionsTests {
#expect(result.trashed.isEmpty)
#expect(result.failures.map(\.url.lastPathComponent) == ["com.example.gone.plist"])
+ #expect(result.failures.map(\.reason) == [.failed(PackageActions.misplacedReceipt)])
+
+ try directory.directory("private/var/db/receipts")
+ let forgotten = await PackageActions.forget(receipt("com.example.gone", on: directory.url), through: service)
+ #expect(forgotten.failures.map(\.reason) == [.failed(PackageActions.forgottenReceipt)], "it was forgotten already")
}
}
diff --git a/Peel/Views/FixedSentenceText.swift b/Peel/Views/FixedSentenceText.swift
index 57c4d5e4..7db9f01f 100644
--- a/Peel/Views/FixedSentenceText.swift
+++ b/Peel/Views/FixedSentenceText.swift
@@ -34,6 +34,7 @@ extension FixedSentence {
case .toolTimedOut: "The tool didn’t answer in time, so it was stopped."
case .toolStopped: "Stopped before it finished."
case .receiptMisplaced: "The receipt isn’t where macOS keeps receipts."
+ case .receiptForgotten: "It was already forgotten."
case .homebrewNotInstalled: "Homebrew isn’t installed."
case .helperUnavailable: "Peel’s helper isn’t available."
}