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
Move nothing else while Peel removes itself
Țugui Dragoș70f78cc808ce
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex 30db2aec..d4c31d5c 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -484,8 +484,9 @@ where a Homebrew install takes them from.Remove Peel, in Settings, takes all of Peel's own files to the Trash but `Terminal/`, the settings zsh and ssh readthrough the user's own lines (`SelfRemoval`), gathered first into one folder named Peel so the Trash shows one item,-and leaves what it changed outside them as it is. It takes no step while Peel's own move would be refused. The-helper moves its own ledger there, since nothing else can, just before Peel unregisters it, and before that the+and leaves what it changed outside them as it is. It takes no step while Peel's own move would be refused. It+starts only while nothing moves, comes back or runs Homebrew (`SelfUninstall.runAlone`), and while it runs nothing+else may (`RemovalHistoryStore.holdingReason`, `.peelRemovesItself`). The helper moves its own ledger there, since nothing else can, just before Peel unregisters it, and before that thelink to the `peel` command when only an administrator can move it (`Uninstallation.unreviewedLinks`): it leads intoPeel until Peel has moved, and the helper takes such a link only when it leads to the tool of the Peel it runs from(`PrivilegedPathPolicy`'s `ownTool`). Both are asked of the helper only once it has answereddiff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex 8570bbf1..4ec93bdf 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -127943,6 +127943,113 @@}}},+ "Peel is removing itself, so it moves nothing else meanwhile." : {+ "comment" : "Why a Move to Trash, a Put Back or an Undo is off for the few seconds Remove Peel runs, since it takes History and Peel’s folder with it.",+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel odstraňuje sám sebe, takže mezitím nic jiného nepřesouvá."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel entfernt sich gerade selbst und verschiebt daher währenddessen nichts anderes."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel se está eliminando, así que mientras tanto no traslada nada más."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel est en train de se supprimer et ne déplace donc rien d’autre pendant ce temps."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel sta rimuovendo sé stesso, quindi nel frattempo non sposta nient’altro."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peelは自身をアンインストールしている最中のため、その間はほかに何も移動しません。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel이 자신을 제거하는 중이므로, 그동안 다른 항목은 이동하지 않습니다."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel is zichzelf aan het verwijderen, dus het verplaatst intussen niets anders."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel się odinstalowuje, więc w tym czasie nie przenosi niczego innego."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "O Peel está se removendo, então não move mais nada enquanto isso."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel se elimină chiar acum, așa că între timp nu mută nimic altceva."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel удаляет себя, поэтому пока больше ничего не перемещает."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel håller på att ta bort sig själv och flyttar därför inget annat under tiden."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel kendini kaldırıyor, bu yüzden bu sırada başka hiçbir şeyi taşımaz."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel вилучає себе, тож тим часом нічого іншого не переміщує."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel正在移除自身,因此在此期间不会移动其他任何内容。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel正在移除自己,因此在此期間不會移動任何其他項目。"+ }+ }+ }+ },"Peel is running from a copy macOS made because it is still marked as downloaded, or from its disk image, and that copy can’t be moved. Quit Peel, move it to the Applications folder, open it there, and choose Remove Peel again." : {"localizations" : {"cs" : {diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swiftindex a4fa9c84..a37f631e 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift@@ -492,6 +492,7 @@ extension TrashFailure.Reason {case .somethingElseMoved(let name): "something else was at that path; it is in the Trash as \(Output.plain(name))"case .historyUnreadable: "History can't be read"case .historyCannotBeWritten: "History can't be written: the disk is full, or Peel's folder can't be written"+ case .peelRemovesItself: "Peel is removing itself"case .heldOpen(let processes) where processes.count > 1:"in use by \(processes.map(Output.plain).joined(separator: ", ")); quit them, or stop them in Background Items if they have no window, then try again"case .heldOpen(let processes):diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swiftindex bc129834..2f1521dc 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift@@ -84,6 +84,8 @@ public struct TrashFailure: Sendable, Hashable {case historyUnreadable/// History cannot be written, as on a full disk, so nothing moves: what moved could not be listed for Put Back.case historyCannotBeWritten+ /// Peel is removing itself, History and its folder with it, so nothing else moves meanwhile.+ case peelRemovesItself/// These processes hold a file open in it, and moving it would pull it from under them.case heldOpen(by: [String])/// Peel itself runs from it or from inside it, and only Remove Peel moves Peel.@@ -119,7 +121,7 @@ extension TrashFailure.Reason {/// state: History it cannot read, or the helper it needs.public var isAboutTheItem: Bool {switch self {- case .historyUnreadable, .historyCannotBeWritten, .needsHelper: false+ case .historyUnreadable, .historyCannotBeWritten, .peelRemovesItself, .needsHelper: falsecase .guarded, .changedSinceScan, .claimedSinceScan, .lastCopy, .notPermitted, .locked, .movedWithoutATrace,.somethingElseMoved, .heldOpen, .peelRunsFromIt, .heldByAnotherAccount, .openForAnotherUser,.heldByABuildTool, .inUseAsAnInputSource, .inUseByMacOS, .attachedDiskImage, .failed: true@@ -148,6 +150,7 @@ extension TrashFailure.Reason {case .somethingElseMoved: "something-else-moved"case .historyUnreadable: "history-unreadable"case .historyCannotBeWritten: "history-cannot-be-written"+ case .peelRemovesItself: "peel-removes-itself"case .heldOpen: "held-open"case .peelRunsFromIt: "peel-runs-from-it"case .heldByAnotherAccount: "held-by-another-account"@@ -189,6 +192,7 @@ extension TrashFailure.Reason {case "something-else-moved": self = .somethingElseMoved(named: detail ?? "")case "history-unreadable": self = .historyUnreadablecase "history-cannot-be-written": self = .historyCannotBeWritten+ case "peel-removes-itself": self = .peelRemovesItselfcase "held-open": self = .heldOpen(by: (detail ?? "").split(separator: "\n").map(String.init))case "peel-runs-from-it": self = .peelRunsFromItcase "held-by-another-account":diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swiftindex 44206637..c0ef6fef 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift@@ -348,11 +348,11 @@ struct RefusalLogTests {}private static let everyReason: [TrashFailure.Reason] = [- .guarded(nil), .changedSinceScan, .claimedSinceScan, .lastCopy, .notPermitted, .needsHelper,+ .guarded(nil), .changedSinceScan, .claimedSinceScan, .lastCopy, .notPermitted, .locked, .needsHelper,.movedWithoutATrace, .somethingElseMoved(named: "x 2"), .historyUnreadable, .historyCannotBeWritten,- .heldOpen(by: ["Figma Agent", "java"]), .peelRunsFromIt, .heldByAnotherAccount(by: ["CtxHelper"]),- .openForAnotherUser(by: ["Spotify"]), .heldByABuildTool(by: ["Gradle"]), .inUseAsAnInputSource,- .inUseByMacOS(by: ["geod", "appleaccountd"]), .failed("x"),+ .peelRemovesItself, .heldOpen(by: ["Figma Agent", "java"]), .peelRunsFromIt,+ .heldByAnotherAccount(by: ["CtxHelper"]), .openForAnotherUser(by: ["Spotify"]), .heldByABuildTool(by: ["Gradle"]),+ .inUseAsAnInputSource, .inUseByMacOS(by: ["geod", "appleaccountd"]), .attachedDiskImage, .failed("x"),] + GuardRefusal.allCases.map { .guarded($0) }/// A record stores its reason as a word, not a sentence, so a later version of Peel can still read it.diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swiftindex 3c51db40..a3047775 100644--- a/Peel/Model/RemovalHistoryStore.swift+++ b/Peel/Model/RemovalHistoryStore.swift@@ -133,6 +133,7 @@ final class RemovalHistoryStore {/// Undo left in the Trash.private let outcome: RemovalOutcome?private let knowsTheExclusions: () -> Bool+ private let removesPeel: () -> Boolprivate let restoring: ([TrashedItem], Bool) async -> [RestoreFailure?]private let announcing: (AttributedString) -> Void/// Read again here once History has counted a removal, rather than by each tool.@@ -206,6 +207,7 @@ final class RemovalHistoryStore {refusals: RefusalLog = RefusalLog(),outcome: RemovalOutcome? = nil,knowsTheExclusions: @escaping () -> Bool = { ExclusionsStore.shared.exclusions.isKnown },+ removesPeel: @escaping () -> Bool = { false },restoring: @escaping ([TrashedItem], Bool) async -> [RestoreFailure?] = { items, canUseHelper inawait TrashService(exclusions: ExclusionsStore.shared.exclusions).restore(items, canUseHelper: canUseHelper)},@@ -217,6 +219,7 @@ final class RemovalHistoryStore {self.refusals = refusalsself.outcome = outcomeself.knowsTheExclusions = knowsTheExclusions+ self.removesPeel = removesPeelself.restoring = restoringself.announcing = announcing}@@ -386,9 +389,10 @@ final class RemovalHistoryStore {/// What the Edit menu shows, and nil when there is nothing to undo.var undoTitle: String? { undoable?.title }- /// Why nothing may move to the Trash or back now: the exclusions are not known, or History can't be read or- /// written.+ /// Why nothing may move to the Trash or back now: Peel is removing itself, the exclusions are not known, or History+ /// can't be read or written.var holdingReason: TrashFailure.Reason? {+ if removesPeel() { return .peelRemovesItself }guard knowsTheExclusions() else { return .guarded(.exclusionsNotKnown) }if isUnreadable { return .historyUnreadable }return cannotBeWritten ? .historyCannotBeWritten : nildiff --git a/Peel/PeelApp.swift b/Peel/PeelApp.swiftindex 42dcf9b8..5ae0809a 100644--- a/Peel/PeelApp.swift+++ b/Peel/PeelApp.swift@@ -71,7 +71,7 @@ struct PeelApp: App {@State private var space: SpaceLibrary@State private var carrier: SelectionCarrier@State private var background = StandingWork()- @State private var selfUninstall = SelfUninstall()+ @State private var selfUninstall: SelfUninstall@State private var textEditing = TextEditing()@State private var sheetInFront = SheetInFront()@State private var hasLaunched = false@@ -91,7 +91,10 @@ struct PeelApp: App {_home = State(initialValue: HomeModel(helper: helper))let outcome = RemovalOutcome()- let (library, history) = (AppLibrary(), RemovalHistoryStore(outcome: outcome))+ let selfUninstall = SelfUninstall()+ _selfUninstall = State(initialValue: selfUninstall)+ let library = AppLibrary()+ let history = RemovalHistoryStore(outcome: outcome, removesPeel: { selfUninstall.isRunning })let (orphans, space, developer, projects) = (OrphanLibrary(), SpaceLibrary(), DeveloperLibrary(), ProjectLibrary())diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swiftindex 350937b7..e2a37195 100644--- a/Peel/Views/Presentation.swift+++ b/Peel/Views/Presentation.swift@@ -180,6 +180,7 @@ extension TrashFailure.Reason {case .somethingElseMoved(let name): String(localized: "Something else was at that path by the time it moved. It is in the Trash as \(name), and Finder can put it back.", bundle: bundle)case .historyUnreadable: String(localized: "Peel couldn’t read History, and it moves nothing it can’t put back.", bundle: bundle)case .historyCannotBeWritten: String(localized: "Peel couldn’t write to History, because the disk is full or Peel’s folder can’t be written, and it moves nothing it can’t put back.", bundle: bundle)+ case .peelRemovesItself: String(localized: "Peel is removing itself, so it moves nothing else meanwhile.", bundle: bundle)case .heldOpen(let processes) where processes.count > 1:String(localized: "It is in use by \(processes.formatted(.list(type: .and))). Quit \(processes.formatted(.list(type: .and))), or stop them in Background Items if they have no window, then try again.", bundle: bundle)case .heldOpen(let processes):diff --git a/PeelTests/RemovalHistoryStoreTests.swift b/PeelTests/RemovalHistoryStoreTests.swiftindex 9c7a9eca..15378487 100644--- a/PeelTests/RemovalHistoryStoreTests.swift+++ b/PeelTests/RemovalHistoryStoreTests.swift@@ -80,6 +80,25 @@ struct RemovalHistoryStoreTests {#expect(later.untoldNoLongerListed == 5)}+ /// Nothing moves or comes back while Peel removes itself, since Remove Peel takes History and Peel's folder.+ @Test func movesNothingWhilePeelRemovesItself() {+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")+ defer { try? FileManager.default.removeItem(at: folder) }+ final class Removal { var runs = false }+ let removal = Removal()+ let history = RemovalHistoryStore(+ log: RemovalLog(url: folder.appending(path: "removals.json")),+ refusals: RefusalLog(url: folder.appending(path: "refusals.json")),+ knowsTheExclusions: { true },+ removesPeel: { removal.runs }+ )++ #expect(history.mayMove)+ removal.runs = true+ #expect(history.holdingReason == .peelRemovesItself)+ #expect(!history.mayMove)+ }+@Test func aHistoryThatCannotBeReadIsNotCalledEmpty() async throws {let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")defer { try? FileManager.default.removeItem(at: folder) }