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.

Take the link to the peel command when Peel removes itself

Țugui Dragoșf205c98a1eb6
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index c913762a..97e35ee3 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -258,7 +258,10 @@ where a Homebrew install takes them from.
| Outside Peel's own files | `~/.hushlogin` from the Terminal page; the Dock's list of icons (`persistent-apps`, through `DockTiles`); the settings Tweaks changes; Terminal's profiles and options; Git's settings; and the Time Machine mark on each folder Build Artifacts leaves out of backups. |
Remove Peel, in Settings, takes all of Peel's own files to the Trash, and leaves what it changed outside them as
-it is. The helper moves its own ledger there, since nothing else can, just before Peel unregisters it. It is the
+it is. The helper moves its own ledger there, since nothing else can, just before Peel unregisters it, and before
+that the link to the `peel` command when only an administrator can move it (`Uninstallation.unreviewedLinks`): it
+leads into Peel 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`). It is the
only way Peel removes itself: Peel's own page in Applications, and Peel among several chosen apps, list it and
select nothing of it (`Uninstallation.isPeel`), and `peel uninstall` refuses it. For a copy Homebrew installed,
Settings shows `brew uninstall --zap` in its place (`SettingsView`).
diff --git a/GUIDE.md b/GUIDE.md
index 12cc7b17..47558c66 100644
--- a/GUIDE.md
+++ b/GUIDE.md
@@ -250,10 +250,11 @@ it.
## Uninstall Peel
-In Settings > General, choose Remove Peel. It has its helper move its record of what it moved to the Trash, removes
-its helper and its login item, moves itself, the files that are certainly its own, and its folder in Application
-Support to the Trash, takes its icon out of the Dock, clears its settings, and quits. That folder holds History, your
-exclusions, and the settings Peel saved when you reset an app.
+In Settings > General, choose Remove Peel. It has its helper move the link to the `peel` command, if you made one in
+Settings, and its record of what it moved to the Trash, removes its helper and its login item, moves itself, the
+files that are certainly its own, and its folder in Application Support to the Trash, takes its icon out of the
+Dock, clears its settings, and quits. That folder holds History, your exclusions, and the settings Peel saved when
+you reset an app.
What Peel changed for you stays as it is: tweaks, Terminal's theme and its options, `~/.hushlogin`, Git's
settings, the build folders you left out of Time Machine, and the background items you disabled. Turn them off
@@ -268,8 +269,8 @@ Trash, and moves Peel's files to the Trash.
brew uninstall --zap --cask peel
```
-If you put the `peel` command on your path from Settings, remove that link too. Homebrew removes only the one it
-made.
+If you put the `peel` command on your path from Settings while Peel's helper isn't installed, or Homebrew installed
+Peel, remove that link yourself. Homebrew removes only the one it made.
```bash
sudo rm -f /usr/local/bin/peel
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/SelfRemoval.swift b/Packages/PeelCore/Sources/PeelCore/Removal/SelfRemoval.swift
index b61ecf74..50891dc8 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/SelfRemoval.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/SelfRemoval.swift
@@ -3,12 +3,13 @@ public import Foundation
/// Moves Peel's own files to the Trash, and then the Peel folder, which holds History.
public enum SelfRemoval {
/// Moves `app` to the Trash, then the rest of `urls` once it has moved, and then `folder`. `record` writes
- /// History into `folder` first, so the record goes with it. Nothing is written after that, or the folder would
- /// be created again.
+ /// History into `folder` first, with `movedFirst`, what the helper moved before it went, so the record goes with
+ /// it. Nothing is written after that, or the folder would be created again.
public static func move(
_ urls: [URL],
app: URL,
folder: URL,
+ movedFirst: [TrashedItem] = [],
using service: TrashService,
recording record: (TrashResult) async -> Void
) async -> TrashResult {
@@ -19,6 +20,7 @@ public enum SelfRemoval {
usingHelperFor: [],
lettingTheirProgramsRun: []
)
+ result.trashed.insert(contentsOf: movedFirst, at: 0)
await record(result)
guard
result.trashed.contains(where: { $0.originalURL == app }),
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
index baeb386d..25752d66 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
@@ -285,19 +285,29 @@ public struct Uninstallation: Sendable {
/// Peel clears its settings. Empty when the app is excluded, kept by macOS, part of another package, or needs
/// the helper: then nothing should start.
public var unreviewedSelection: [URL] {
- guard !isExcluded, !app.isSystemProtected, app.enclosingPackage == nil, !appRequiresPrivileges else {
- return []
- }
- let namespace = app.bundleIdentifier.lowercased() + "."
- let own = scan.leftovers.filter { leftover in
- let match = leftover.match
- return match.sharedWith.isEmpty && match.heldBack == nil && match.confidence >= .likely
- && !leftover.requiresPrivileges
- && (match.confidence == .certain || leftover.url.lastPathComponent.lowercased().hasPrefix(namespace))
- }
+ guard movesUnreviewed else { return [] }
+ let own = scan.leftovers.filter { isUnreviewedOwn($0) && !$0.requiresPrivileges }
return order(of: Set(own.map(\.url)).union([app.url]))
}
+ /// The app's own links in the folders only an administrator can change, chosen as `unreviewedSelection` chooses,
+ /// which Remove Peel hands to the helper before the helper goes.
+ public var unreviewedLinks: [URL] {
+ guard movesUnreviewed else { return [] }
+ return scan.leftovers.filter { isUnreviewedOwn($0) && $0.requiresPrivileges && $0.kind.isForLinks }.map(\.url)
+ }
+
+ private var movesUnreviewed: Bool {
+ !isExcluded && !app.isSystemProtected && app.enclosingPackage == nil && !appRequiresPrivileges
+ }
+
+ private func isUnreviewedOwn(_ leftover: Leftover) -> Bool {
+ let match = leftover.match
+ let namespace = app.bundleIdentifier.lowercased() + "."
+ return match.sharedWith.isEmpty && match.heldBack == nil && match.confidence >= .likely
+ && (match.confidence == .certain || leftover.url.lastPathComponent.lowercased().hasPrefix(namespace))
+ }
+
/// How many items could move once selected, and their total size: what a section header shows and the
/// page's total adds up. Rows Peel leaves alone are not counted.
public func movable(among leftovers: [Leftover], withApp: Bool) -> (count: Int, size: SizeTotal) {
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/HelperInterface.swift b/Packages/PeelCore/Sources/PeelPrivileged/HelperInterface.swift
index a959bee2..91af2904 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/HelperInterface.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/HelperInterface.swift
@@ -7,7 +7,7 @@ public enum HelperIdentity {
public static let launchdPlistName = "com.tuguidragos.Peel.Helper.plist"
/// Raise it whenever the helper changes, so Peel asks for the helper to be installed again rather than work with
/// an older one. The helper refuses requests that carry any other version.
- public static let protocolVersion = 12
+ public static let protocolVersion = 13
}
/// The complete set of privileged operations. The helper validates every argument itself.
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/PrivilegedPathPolicy.swift b/Packages/PeelCore/Sources/PeelPrivileged/PrivilegedPathPolicy.swift
index c8065351..1f0250f5 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/PrivilegedPathPolicy.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/PrivilegedPathPolicy.swift
@@ -62,7 +62,8 @@ public struct PrivilegedPathPolicy: Sendable {
]
/// The folders command-line tools and their shell completions are linked into. The helper takes only a link from
- /// them, and only one that leads nowhere: what an app's tool leaves there once the app is gone.
+ /// them, and only one that leads nowhere: what an app's tool leaves there once the app is gone. The one exception
+ /// is a link to Peel's own tool, which Remove Peel hands over while Peel is still in place (`ownTool`).
public static let linkLocations = ["/usr/local/bin", "/usr/local/sbin"]
+ shellCompletionFolders.map { "/usr/local/" + $0 }
@@ -78,6 +79,8 @@ public struct PrivilegedPathPolicy: Sendable {
private let restorable: [String]
private let applicationLocations: [String]
private let links: [String]
+ /// The device and inode of the `peel` tool inside the app the helper runs from.
+ private let ownTool: (device: dev_t, inode: ino_t)?
/// The folders of the home's Library that Peel searches, lowercased, as names from the root.
private let searchedFolders: Set<[String]>
private let homeDirectory: String
@@ -89,11 +92,17 @@ public struct PrivilegedPathPolicy: Sendable {
applicationLocations: [String] = ["/Applications"],
restoreLocations: [String] = Self.restoreLocations,
linkLocations: [String] = Self.linkLocations,
+ ownTool: String? = nil,
trustedOwner: uid_t = 0
) {
self.homeDirectory = homeDirectory
self.trustedOwner = trustedOwner
links = linkLocations.compactMap(Self.realPath)
+ self.ownTool = ownTool.flatMap { path in
+ var info = stat()
+ guard stat(path, &info) == 0 else { return nil }
+ return (info.st_dev, info.st_ino)
+ }
locations = (systemLocations + [homeDirectory + "/Library"]).compactMap(Self.realPath) + links
restorable = (restoreLocations + [homeDirectory + "/Library"]).compactMap(Self.realPath)
self.applicationLocations = applicationLocations.compactMap(Self.realPath)
@@ -103,6 +112,16 @@ public struct PrivilegedPathPolicy: Sendable {
})
}
+ /// The `peel` tool of the app whose `Contents/MacOS` holds `executable`, where launchd starts the helper
+ /// (`BundleProgram`), or nil for an executable anywhere else.
+ public static func peelTool(besideHelperAt executable: String) -> String? {
+ let names = PathComponents.of(executable)
+ guard names.count >= 4, Array(names.suffix(3).dropLast()) == ["Contents", "MacOS"],
+ names[names.count - 4].hasSuffix(".app")
+ else { return nil }
+ return "/" + (names.dropLast(2) + ["Helpers", "peel"]).joined(separator: "/")
+ }
+
/// True for a path directly in one of the folders the helper takes only a link from.
public func takesOnlyALink(at path: String) -> Bool {
guard let parent = Self.realPath((path as NSString).deletingLastPathComponent) else { return false }
@@ -188,7 +207,8 @@ public struct PrivilegedPathPolicy: Sendable {
var target = stat()
let leads = item.name.withCString { fstatat(parent.descriptor, $0, &target, 0) } == 0
let error = errno
- guard !leads, error == ENOENT || error == ENOTDIR || error == ELOOP else {
+ let isOwnTool = leads && ownTool.map { $0 == (target.st_dev, target.st_ino) } == true
+ guard isOwnTool || !leads && (error == ENOENT || error == ENOTDIR || error == ELOOP) else {
return .failure(.leadsSomewhere)
}
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PrivilegedPathPolicyTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PrivilegedPathPolicyTests.swift
index 57749015..5dce338f 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/PrivilegedPathPolicyTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/PrivilegedPathPolicyTests.swift
@@ -15,7 +15,8 @@ struct PrivilegedPathPolicyTests {
/// test cannot make a file root's, so a test may pass its own user ID instead.
private func policy(
in directory: borrowing TemporaryDirectory,
- trustedOwner: uid_t = 0
+ trustedOwner: uid_t = 0,
+ ownTool: String? = nil
) throws -> PrivilegedPathPolicy {
try directory.directory("root/Library/LaunchDaemons")
try directory.directory("root/Applications")
@@ -29,6 +30,7 @@ struct PrivilegedPathPolicyTests {
applicationLocations: [root + "root/Applications"],
restoreLocations: [root + "root/Applications", root + "root/Library/Caches"],
linkLocations: [root + "root/usr/local/bin"],
+ ownTool: ownTool,
trustedOwner: trustedOwner
)
}
@@ -98,6 +100,42 @@ struct PrivilegedPathPolicyTests {
#expect(policy.openDestination(path("root/usr/local/bin/gone2", in: directory), for: trashedLink).map(\.name) == .success("gone2"))
}
+ /// Remove Peel hands the helper the link to Peel's own tool while the app is still in place, so that link goes
+ /// though it leads somewhere. A link to anything else still stays.
+ @Test func takesTheLinkToThePeelToolOfTheAppItRunsFrom() throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("root/Applications/Peel.app/Contents/Helpers/peel")
+ try directory.file("root/Applications/Peel.app/Contents/MacOS/Peel")
+ try directory.file("root/Applications/Other.app/Contents/Helpers/peel")
+ let helper = path("root/Applications/Peel.app/Contents/MacOS/PeelHelper", in: directory)
+ let tool = try #require(PrivilegedPathPolicy.peelTool(besideHelperAt: helper))
+ let policy = try policy(in: directory, ownTool: tool)
+ func link(_ name: String, to destination: String) throws {
+ try FileManager.default.createSymbolicLink(
+ atPath: path("root/usr/local/bin/\(name)", in: directory),
+ withDestinationPath: destination
+ )
+ }
+ try link("peel", to: tool)
+ try link("relative", to: "../../../Applications/Peel.app/Contents/Helpers/peel")
+ try link("other", to: path("root/Applications/Other.app/Contents/Helpers/peel", in: directory))
+ try link("app", to: path("root/Applications/Peel.app/Contents/MacOS/Peel", in: directory))
+
+ for name in ["peel", "relative"] {
+ #expect((try? policy.open(path("root/usr/local/bin/\(name)", in: directory)).get()) != nil, "\(name)")
+ }
+ for name in ["other", "app"] {
+ let opened = policy.open(path("root/usr/local/bin/\(name)", in: directory))
+ #expect(opened.map(\.name) == .failure(.leadsSomewhere))
+ }
+ let withoutTool = try self.policy(in: directory)
+ let opened = withoutTool.open(path("root/usr/local/bin/peel", in: directory))
+ #expect(opened.map(\.name) == .failure(.leadsSomewhere))
+ #expect(PrivilegedPathPolicy.peelTool(besideHelperAt: "/usr/local/libexec/PeelHelper") == nil)
+ #expect(PrivilegedPathPolicy.peelTool(besideHelperAt: "/opt/Tools/Contents/MacOS/PeelHelper") == nil)
+ #expect(PrivilegedPathPolicy.peelTool(besideHelperAt: "/Applications/Peel.app/Contents/Helpers/peel") == nil)
+ }
+
/// A browser profile with a wallet extension's vault stays, and so does every folder around it, while the rest
/// of the profile can still go.
@Test func refusesAFolderHoldingABrowserWallet() throws {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift
index 9aff93bd..4c50012a 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift
@@ -49,6 +49,31 @@ struct SelfRemovalTests {
#expect(try String(contentsOf: moved.trashedURL.appending(path: "removals.json"), encoding: .utf8) == "2")
}
+ /// 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()
+ let app = try directory.directory("home/Applications/Peel.app")
+ let folder = try directory.directory("home/Library/Application Support/Peel")
+ let link = TrashedItem(
+ originalURL: URL(filePath: "/usr/local/bin/peel"),
+ trashedURL: directory.url.appending(path: "Trash/peel"),
+ date: .now,
+ identity: nil
+ )
+ var recorded: [URL] = []
+
+ let result = await SelfRemoval.move(
+ [app],
+ app: app,
+ folder: folder,
+ movedFirst: [link],
+ using: try service(in: directory)
+ ) { recorded = $0.trashed.map(\.originalURL) }
+
+ #expect(paths(recorded) == paths([link.originalURL, app]))
+ #expect(paths(result.trashed.map(\.originalURL)) == paths([link.originalURL, app, folder]))
+ }
+
/// When the app stays, its files and its folder stay too: Peel goes on using them.
@Test func leavesTheFolderWhenTheAppStayed() async throws {
let directory = try TemporaryDirectory()
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
index 4043c4fc..90f5109a 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
@@ -50,6 +50,29 @@ struct UninstallationTests {
#expect(uninstallation(appRequiresPrivileges: true, leftovers: [own]).unreviewedSelection.isEmpty)
}
+ /// Remove Peel hands the helper the app's own links in a folder only an administrator can change, and nothing
+ /// else that needs the helper.
+ @Test func handsTheHelperOnlyItsOwnLinksWhenNobodyReviewsTheList() {
+ func link(_ name: String, sharedWith: [String] = []) -> Leftover {
+ Leftover(
+ url: URL(filePath: "/usr/local/bin/\(name)"),
+ kind: .commandLineTools,
+ match: LeftoverMatch(reason: .linksToTheApp, confidence: .certain, sharedWith: sharedWith),
+ size: 0,
+ isMeasured: true,
+ requiresPrivileges: true
+ )
+ }
+ let tool = link("example")
+ let shared = link("shared", sharedWith: ["com.example.other"])
+ let daemon = leftover("daemon.plist", requiresPrivileges: true)
+ let plan = uninstallation(leftovers: [tool, shared, daemon])
+
+ #expect(plan.unreviewedLinks == [tool.url])
+ #expect(!plan.unreviewedSelection.contains(tool.url))
+ #expect(uninstallation(appRequiresPrivileges: true, leftovers: [tool]).unreviewedLinks.isEmpty)
+ }
+
@Test func selectsTheAppAndRecommendedLeftovers() {
let recommended = leftover("recommended")
let shared = leftover("shared", sharedWith: ["com.example.other"])
diff --git a/Peel/Model/SelfUninstall.swift b/Peel/Model/SelfUninstall.swift
index 50513b8f..85a92ac6 100644
--- a/Peel/Model/SelfUninstall.swift
+++ b/Peel/Model/SelfUninstall.swift
@@ -17,10 +17,13 @@ final class SelfUninstall {
"sudo rm -f /usr/local/bin/peel"
}
- /// True only when `/usr/local/bin/peel` is Peel's own tool. For another program's `peel`, `removeCommand`
- /// would delete a file that is not Peel's.
- var hasCommandLineTool: Bool {
- CommandLineTool.standing(embedded: Bundle.main.bundleURL.appending(path: "Contents/Helpers/peel")) == .installed
+ /// Whether Remove Peel would leave `/usr/local/bin/peel` while it is Peel's own tool: only an administrator can
+ /// move it, and the helper that would is not enabled. For another program's `peel`, `removeCommand` would delete
+ /// a file that is not Peel's.
+ func leavesCommandLineTool(helper status: PrivilegedHelper.Status) -> Bool {
+ let embedded = Bundle.main.bundleURL.appending(path: "Contents/Helpers/peel")
+ return status != .enabled && CommandLineTool.standing(embedded: embedded) == .installed
+ && FileAccess.requiresPrivilegesToRemove(URL(filePath: CommandLineTool.path))
}
/// Removes Peel. The plan is made first, and the steps nothing can undo (unregistering the helper and the
@@ -52,8 +55,8 @@ final class SelfUninstall {
return
}
let exclusions = ExclusionsStore.shared.exclusions
- let urls = await Uninstallation.prepare(app, installedApps: installedApps, exclusions: exclusions)
- .unreviewedSelection
+ let plan = await Uninstallation.prepare(app, installedApps: installedApps, exclusions: exclusions)
+ let urls = plan.unreviewedSelection
guard !urls.isEmpty else {
failure = String(localized: "Peel won’t move itself from here: its folder needs an administrator, or Peel is excluded in Settings. Drag it to the Trash in Finder, which asks for an administrator when one is needed.")
return
@@ -62,12 +65,20 @@ final class SelfUninstall {
work.pause()
let isRegistered = { [helper] in helper.status == .enabled || helper.status == .requiresApproval }
var ledger = PrivilegedHelper.LedgerMove.none
+ var links = TrashResult()
if isRegistered() {
+ if helper.status == .enabled {
+ let own = plan.unreviewedLinks
+ links = await TrashService(exclusions: exclusions).trash(own, usingHelperFor: Set(own))
+ }
ledger = await PrivilegedHelper.moveLedgerToTrash()
await helper.uninstall()
// A helper still registered would point into the Trash, so Peel moves only once the helper is gone.
guard !isRegistered() else {
work.resume()
+ if !links.trashed.isEmpty {
+ await record(TrashResult(trashed: links.trashed))
+ }
let reason = helper.failure?.reason ?? String(localized: "The helper couldn’t be removed, so Peel stayed where it was.")
failure = ledger == .moved ? "\(reason)\n\n\(Self.ledgerInTheTrash)" : reason
return
@@ -81,6 +92,7 @@ final class SelfUninstall {
urls,
app: bundleURL,
folder: PeelFolder.url,
+ movedFirst: links.trashed,
using: TrashService(exclusions: exclusions),
recording: record
)
@@ -91,7 +103,7 @@ final class SelfUninstall {
return
}
_ = await DockTiles().takeOut([bundleURL], remembering: false)
- var stayed = result.failures
+ var stayed = result.failures + links.failures
if case .stayed(let failure) = ledger {
stayed.append(failure)
}
diff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swift
index a6d3c521..bcd69030 100644
--- a/Peel/Views/Settings/SettingsView.swift
+++ b/Peel/Views/Settings/SettingsView.swift
@@ -419,7 +419,8 @@ private struct GeneralSettingsView: View {
}
}
// Homebrew removes the links its cask made, and no other.
- if selfUninstall.hasCommandLineTool, ownCask?.commandLinks.contains(CommandLineTool.path) != true {
+ if selfUninstall.leavesCommandLineTool(helper: helper.status),
+ ownCask?.commandLinks.contains(CommandLineTool.path) != true {
VStack(alignment: .leading, spacing: 4) {
Text("Removing Peel leaves the peel command in place. To remove it too, run this command in Terminal:")
.font(.callout)
diff --git a/PeelHelper/HelperService.swift b/PeelHelper/HelperService.swift
index 4d6d02fe..b2641c04 100644
--- a/PeelHelper/HelperService.swift
+++ b/PeelHelper/HelperService.swift
@@ -23,6 +23,14 @@ final class HelperService: NSObject, PeelHelperProtocol {
return HelperRequest.Caller(user: user, homeDirectory: home)
}
+ /// The `peel` tool of the app the helper runs from, found from the program the kernel says it runs.
+ private static let ownTool: String? = {
+ var buffer = [CChar](repeating: 0, count: 4 * Int(MAXPATHLEN))
+ guard proc_pidpath(getpid(), &buffer, UInt32(buffer.count)) > 0 else { return nil }
+ let path = String(decoding: buffer.prefix { $0 != 0 }.map { UInt8(bitPattern: $0) }, as: UTF8.self)
+ return PrivilegedPathPolicy.peelTool(besideHelperAt: path)
+ }()
+
private func tracked(_ finish: @escaping @Sendable (String?) -> Void) -> @Sendable (String?) -> Void {
{ [lifetime] answer in
finish(answer)
@@ -54,7 +62,7 @@ final class HelperService: NSObject, PeelHelperProtocol {
return refuse(error.rawValue)
}
- let policy = PrivilegedPathPolicy(homeDirectory: caller.homeDirectory)
+ let policy = PrivilegedPathPolicy(homeDirectory: caller.homeDirectory, ownTool: Self.ownTool)
guard let trash = policy.openTrash(ownedBy: caller.user) else { return refuse(HelperRefusal.noTrash.rawValue) }
var failed: [String: String] = [:]
diff --git a/SAFETY.md b/SAFETY.md
index f568ec83..627fe70c 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -43,8 +43,9 @@ In the Library of every account on the Mac and, for the last rows, in the home f
Outside your home: everything inside `/System`, `/usr`, `/bin`, `/sbin`, and `/Library/Updates`, where macOS
stages its own updates, but for two things: a link that leads nowhere, directly in `/usr/local/bin`,
`/usr/local/sbin`, or one of the four folders of `/usr/local` that shell completions are linked into, which an
-app's tool or its completion leaves there once the app is gone and the helper may take (see [The helper that
-runs as root](#the-helper-that-runs-as-root)); and a folder directly in `/usr/local/Caskroom`, the record
+app's tool or its completion leaves there once the app is gone and the helper may take, or Peel's own link to its
+`peel` command, which Remove Peel hands the helper (see [The helper that runs as
+root](#the-helper-that-runs-as-root)); and a folder directly in `/usr/local/Caskroom`, the record
Homebrew keeps of an app it installed on an Intel Mac, which goes with the app. And these folders themselves,
though not what is inside them:
`/`, `/Applications`, `/Library`, `/Users`, `/Users/Shared`, `/Volumes`, `/opt`, `/private` and its `var`,
@@ -411,7 +412,8 @@ and it fails closed.
`/usr/local/sbin`, and the completion folders of `/usr/local` (`share/zsh/site-functions`,
`share/fish/vendor_completions.d`, `etc/bash_completion.d`, and `share/pwsh/completions`), it takes only a link,
never a file, and only one that leads nowhere. Peel sends an app's links there after the app itself, so they go
- once the app is gone, and a link that still leads to something stays.
+ once the app is gone, and a link that still leads to something stays. The one exception is a link to the `peel`
+ command inside the Peel the helper runs from, which Remove Peel hands it before the helper goes.
- It never reuses a path after checking it. It opens the parent directory, checks the item there as the system
names that directory, works only through that descriptor, and moves the item only while it is still the one it
checked, so a folder or an item swapped after the check leads nowhere.