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.

Never move a folder Peel runs from

Țugui Dragoșf63471b07545
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index 1fa836a4..885f3f01 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -107,6 +107,8 @@ Take the most common case, uninstalling an app. Every other page follows the sam
a file open only for reading holds nothing, and neither does the program running from an app that
uninstalls itself once it has moved (`UninstallsItself`, Mullvad VPN's daemon), whose uninstaller's files
are held back (`leftToItsUninstaller`) rather than moved first.
+ - What Peel itself runs from never moves, nor anything holding it, such as the folder a copy built from source
+ runs from: only Remove Peel moves Peel (`TrashFailure.Reason.peelRunsFromIt`).
- The app's privacy permissions are reset, when that was chosen, just before the move and only once the
checks the move makes first (the guard, History, and the programs holding it) say it will go
(`PrivacyReset`).
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 17afc32d..a973d391 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -105055,6 +105055,112 @@
}
}
},
+ "Peel itself runs from here, and only Remove Peel, in Settings > General, removes Peel." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Odtud běží samotný Peel a odstranit ho lze jen volbou „Odstranit Peel“ v Nastavení > Obecné."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel selbst wird von hier aus ausgeführt und nur mit „Peel entfernen“ unter „Einstellungen“ > „Allgemein“ entfernt."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "El propio Peel se ejecuta desde aquí, y solo “Eliminar Peel”, en Ajustes > General, elimina Peel."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel lui-même s’exécute à partir de cet emplacement, et seul « Supprimer Peel », dans Réglages > Général, supprime Peel."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel stesso viene eseguito da qui, e solo “Rimuovi Peel”, in Impostazioni > Generali, rimuove Peel."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel自体がここから実行されており、Peelを取り除けるのは“設定”>“一般”にある“Peelをアンインストール”だけです。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel 자체가 여기에서 실행되며, Peel은 설정 > 일반에 있는 ‘Peel 제거’로만 제거할 수 있습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel zelf wordt van hieruit uitgevoerd, en alleen 'Verwijder Peel' in Instellingen > Algemeen verwijdert Peel."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Z tego miejsca działa sam Peel, a odinstalowuje go tylko „Odinstaluj Peel” w Ustawieniach > Ogólne."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O próprio Peel é executado a partir daqui, e só “Remover o Peel”, em Ajustes > Geral, remove o Peel."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel însuși rulează de aici și doar „Eliminați Peel”, din Configurări > General, elimină Peel."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Отсюда запущен сам Peel, а удалить Peel можно только с помощью пункта «Удалить Peel» в разделе «Настройки» > «Основные»."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel själv körs härifrån, och bara ”Ta bort Peel” i Inställningar > Allmänt tar bort Peel."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel’in kendisi buradan çalışıyor ve Peel yalnızca Ayarlar > Genel’deki “Peel’i Kaldır” ile kaldırılır."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Звідси працює сама Peel, і лише команда «Вилучити Peel» у розділі Параметри > Загальні вилучає Peel."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel本身正从此处运行,并且只有“设置”>“通用”中的“移除Peel”才能移除Peel。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel本身正從這裡執行,而且只有「設定」>「一般」中的「移除Peel」才能移除Peel。"
+ }
+ }
+ }
+ },
"Peel kept the old file and continued with what it could still read." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index adaedcfa..a477fac4 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -409,6 +409,7 @@ extension TrashFailure.Reason {
case .historyUnreadable: "History can't be read"
case .heldOpen(let processes):
"in use by \(processes.map(Output.plain).joined(separator: ", ")); quit \(processes.count == 1 ? "it" : "them") and try again"
+ case .peelRunsFromIt: "Peel runs from here; only Remove Peel, in the app's Settings > General, removes Peel"
case .failed(let message): Output.plain(message)
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swift b/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swift
index deb744b7..574bb927 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swift
@@ -9,10 +9,13 @@ struct OpenFiles {
private enum Hold { case reads, writes, runs }
private let files: [(names: [String], process: String, hold: Hold)]
+ /// The program the excluded process runs. Its open files are no hold, but where it runs from is.
+ private let excludedProgram: [String]?
/// Each regular file held open for reading or writing, and the program each process runs, which it holds as long
/// as it runs. A watch (`O_EVTONLY`, as Finder keeps on what it shows) and a folder are no hold on what is inside.
init(excluding excluded: pid_t? = getpid()) {
+ excludedProgram = excluded.flatMap(RunningProgram.path(of:)).map(PathComponents.of)
var pids = [pid_t](repeating: 0, count: 8_192)
let count = Int(proc_listallpids(&pids, Int32(pids.count * MemoryLayout<pid_t>.size)))
var files: [(names: [String], process: String, hold: Hold)] = []
@@ -42,6 +45,11 @@ struct OpenFiles {
return Set(holding.map(\.process)).sorted()
}
+ func runsTheExcludedProcess(from url: URL, lettingItsProgramsRun: Bool = false) -> Bool {
+ guard !lettingItsProgramsRun, let excludedProgram else { return false }
+ return excludedProgram.starts(with: PathComponents.of(PathPattern.canonical(url).path(percentEncoded: false)))
+ }
+
private static func paths(openBy pid: pid_t) -> [(path: String, hold: Hold)] {
let size = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, nil, 0)
guard size > 0 else { return [] }
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/SelfRemoval.swift b/Packages/PeelCore/Sources/PeelCore/Removal/SelfRemoval.swift
index af682e9c..c3d3dcc2 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/SelfRemoval.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/SelfRemoval.swift
@@ -19,7 +19,7 @@ public enum SelfRemoval {
apps: urls.filter { $0 == app },
thenFiles: { stayed in stayed.isEmpty ? files : [] },
usingHelperFor: [],
- lettingTheirProgramsRun: []
+ lettingTheirProgramsRun: [app]
)
result.trashed.insert(contentsOf: movedFirst, at: 0)
await record(result)
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
index 36eeb2de..3ccd5033 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
@@ -83,6 +83,8 @@ public struct TrashFailure: Sendable, Hashable {
case historyUnreadable
/// 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.
+ case peelRunsFromIt
case failed(String)
}
@@ -102,7 +104,7 @@ extension TrashFailure.Reason {
switch self {
case .historyUnreadable, .needsHelper: false
case .guarded, .changedSinceScan, .claimedSinceScan, .lastCopy, .notPermitted, .locked, .movedWithoutATrace,
- .somethingElseMoved, .heldOpen, .failed: true
+ .somethingElseMoved, .heldOpen, .peelRunsFromIt, .failed: true
}
}
@@ -121,6 +123,7 @@ extension TrashFailure.Reason {
case .somethingElseMoved: "something-else-moved"
case .historyUnreadable: "history-unreadable"
case .heldOpen: "held-open"
+ case .peelRunsFromIt: "peel-runs-from-it"
case .failed: "failed"
}
}
@@ -152,6 +155,7 @@ extension TrashFailure.Reason {
case "something-else-moved": self = .somethingElseMoved(named: detail ?? "")
case "history-unreadable": self = .historyUnreadable
case "held-open": self = .heldOpen(by: (detail ?? "").split(separator: "\n").map(String.init))
+ case "peel-runs-from-it": self = .peelRunsFromIt
case "failed": self = .failed(detail ?? "")
default: return nil
}
@@ -293,6 +297,8 @@ public struct TrashService: Sendable {
for url in urls {
if let refusal = refusal(of: url) {
refusals[url] = refusal
+ } else if openFiles.runsTheExcludedProcess(from: url, lettingItsProgramsRun: apps.contains(url)) {
+ refusals[url] = .peelRunsFromIt
} else if case let holders = openFiles.holders(of: url, lettingItsProgramsRun: apps.contains(url)),
!holders.isEmpty {
refusals[url] = .heldOpen(by: holders)
@@ -356,6 +362,10 @@ public struct TrashService: Sendable {
// An item inside a folder that just moved went with it: it is neither moved again nor a failure.
let path = PathPattern.comparablePath(of: url)
guard !moved.hold(path) else { continue }
+ guard !openFiles.runsTheExcludedProcess(from: url, lettingItsProgramsRun: apps.contains(url)) else {
+ result.failures.append(TrashFailure(url: url, reason: .peelRunsFromIt))
+ continue
+ }
let holders = openFiles.holders(of: url, lettingItsProgramsRun: apps.contains(url))
guard holders.isEmpty else {
result.failures.append(TrashFailure(url: url, reason: .heldOpen(by: holders)))
@@ -456,6 +466,10 @@ public struct TrashService: Sendable {
var allowed: [URL] = []
for url in permitted {
guard !paths.hold(PathPattern.comparablePath(of: url)) else { continue }
+ guard !openFiles.runsTheExcludedProcess(from: url, lettingItsProgramsRun: apps.contains(url)) else {
+ result.failures.append(TrashFailure(url: url, reason: .peelRunsFromIt))
+ continue
+ }
let holders = openFiles.holders(of: url, lettingItsProgramsRun: apps.contains(url))
guard holders.isEmpty else {
result.failures.append(TrashFailure(url: url, reason: .heldOpen(by: holders)))
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift
index ebf01d7f..94039f88 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift
@@ -215,7 +215,7 @@ struct RefusalLogTests {
private static let everyReason: [TrashFailure.Reason] = [
.guarded(nil), .changedSinceScan, .claimedSinceScan, .lastCopy, .notPermitted, .needsHelper,
.movedWithoutATrace, .somethingElseMoved(named: "x 2"), .historyUnreadable,
- .heldOpen(by: ["Figma Agent", "java"]), .failed("x"),
+ .heldOpen(by: ["Figma Agent", "java"]), .peelRunsFromIt, .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/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift
index 792b61e4..4a1d09d2 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift
@@ -1,5 +1,6 @@
import Foundation
@testable import PeelCore
+import PeelPrivileged
import Testing
struct SelfRemovalTests {
@@ -49,6 +50,23 @@ struct SelfRemovalTests {
#expect(try String(contentsOf: moved.trashedURL.appending(path: "removals.json"), encoding: .utf8) == "2")
}
+ @Test func movesTheAppPeelRunsFrom() async throws {
+ let directory = try TemporaryDirectory()
+ let program = try #require(RunningProgram.path(of: getpid()))
+ let app = URL(filePath: program).deletingLastPathComponent()
+ let folder = try directory.directory("home/Library/Application Support/Peel")
+ let environment = SearchEnvironment(
+ homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),
+ rootDirectory: directory.url.appending(path: "root", directoryHint: .isDirectory)
+ )
+
+ let service = TrashService(environment: environment) { $0 }
+
+ let result = await SelfRemoval.move([app], app: app, folder: folder, using: service) { _ in }
+
+ #expect(!result.failures.contains { $0.reason == .peelRunsFromIt })
+ }
+
/// The link the helper moved before it went is written into History with the rest, as one removal.
@Test func recordsWhatTheHelperMovedFirstWithTheRest() async throws {
let directory = try TemporaryDirectory()
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
index 6ef1d977..135fda3e 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
@@ -781,6 +781,25 @@ struct TrashServiceTests {
])
}
+ @Test func leavesTheFolderThisVeryProgramRunsFrom() async throws {
+ let directory = try TemporaryDirectory()
+ let program = try #require(RunningProgram.path(of: getpid()))
+ let folder = URL(filePath: program).deletingLastPathComponent()
+ let environment = SearchEnvironment(
+ homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),
+ rootDirectory: directory.url.appending(path: "root", directoryHint: .isDirectory)
+ )
+ let service = TrashService(environment: environment) { $0 }
+
+ let result = await service.trash([folder])
+ let throughTheHelper = await service.trash([folder], usingHelperFor: [folder])
+
+ #expect(result.trashed.isEmpty)
+ #expect(result.failures.map(\.reason) == [.peelRunsFromIt])
+ #expect(throughTheHelper.failures.map(\.reason) == [.peelRunsFromIt])
+ #expect(service.refusalsNow(of: [folder], lettingTheirProgramsRun: []) == [folder: .peelRunsFromIt])
+ }
+
@Test func leavesAFolderAnotherProcessHoldsAFileOpenIn() async throws {
let directory = try TemporaryDirectory()
let service = try service(in: directory)
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index 1282b328..e41e3479 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -154,6 +154,7 @@ extension TrashFailure.Reason {
case .historyUnreadable: String(localized: "Peel couldn’t read History, and it moves nothing it can’t put back.")
case .heldOpen(let processes):
String(localized: "It is in use by \(processes.formatted(.list(type: .and))). Quit \(processes.formatted(.list(type: .and))), then try again.")
+ case .peelRunsFromIt: String(localized: "Peel itself runs from here, and only Remove Peel, in Settings > General, removes Peel.")
case .failed(let message): FixedSentence.translated(message)
}
}
diff --git a/SAFETY.md b/SAFETY.md
index 7d886544..ef9d4427 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -144,10 +144,11 @@ process runs, and leaves where it is any file or folder with one of them inside,
database or a cache from under an agent, a daemon, or a server that is using it would break it. An app is code,
which loses nothing when it moves, so a program that only reads inside it, as Safari reads an app's Safari
extension, does not keep it in place; one that runs from it or writes in it does, unless the app uninstalls itself
-once it is moved, as Mullvad VPN does: the program running from it is the one that cleans up. Of programs that run as
-another account or as root, macOS's own among them, only the program can be seen, never the files it holds open,
-which is why Space also leaves macOS's own caches unselected, and in the Library at the top of the disk, where those
-programs keep theirs, does not list them at all.
+once it is moved, as Mullvad VPN does: the program running from it is the one that cleans up. Peel itself counts
+too: whatever Peel runs from, and any folder holding it, stays, since only Remove Peel moves Peel. Of programs that
+run as another account or as root, macOS's own among them, only the program can be seen, never the files it holds
+open, which is why Space also leaves macOS's own caches unselected, and in the Library at the top of the disk, where
+those programs keep theirs, does not list them at all.
A move to the Trash, or back from it, never replaces what is already at the new name. Most disks refuse that by
themselves; on one that cannot, such as exFAT, Peel first takes the name with an empty placeholder, which only a