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.

Keep a folder Peel can't search for an app you excluded

Țugui Dragoșa1282714e9c6
diff --git a/AGENTS.md b/AGENTS.md
index 880b5b21..e9f4e9dc 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -142,7 +142,8 @@ checked by hand. If a change makes one of them fail, the rule is right and the c
(`lstat` answering `ENOENT`) makes one of Peel's own files empty; anything else reads as unreadable, and while
History or the exclusions can't be read, nothing moves. The guard's rules that look a level or two inside a folder
answer `ProtectedData.Finding`, and a folder with one inside they couldn't list is refused, unless only the helper
- can move it, which looks inside as root.
+ can move it, which looks inside as root. The exclusions' look for an excluded app answers nil the same way
+ (`Exclusions.appFolders(inside:)`), which refuses even what the helper would move: the helper has no exclusions.
## The privileged helper
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1db932f3..65de5bfa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -234,6 +234,9 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.
- A folder with a folder inside that macOS won't let Peel list is refused, by the app and by the helper, since a photo
library, a browser's wallet, or work an app keeps only in a cache may be in there, and its row says so. One only an
administrator can move is left to the helper, which looks inside as root.
+- While you exclude an app, such a folder stays even when only the helper could move it, since a folder of the app you
+ excluded may be in there and the helper knows nothing of your exclusions; the Homebrew page doesn't run
+ `brew uninstall` on a package with one.
## 1.1.0 (2026-10-14)
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index abb985c7..526d6aa7 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -22159,6 +22159,112 @@
}
}
},
+ "Can’t be checked against your exclusions" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nelze porovnat s vašimi výjimkami"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Abgleich mit deinen Ausschlüssen nicht möglich"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "No se puede comparar con tus exclusiones"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Impossible de vérifier par rapport à vos exclusions"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Impossibile confrontarlo con le tue esclusioni"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "除外リストと照合できません"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "제외 항목과 대조할 수 없음"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Kan niet worden gecontroleerd aan de hand van je uitsluitingen"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie można sprawdzić pod kątem Twoich wykluczeń"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Não é possível comparar com as suas exclusões"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nu poate fi verificat în raport cu excluderile dvs."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не удается сверить с Вашими исключениями"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Kan inte kontrolleras mot dina undantag"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Hariç tutulanlarınızla karşılaştırılamıyor"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не вдається перевірити за вашими винятками"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "无法对照你的排除项进行检查"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "無法依據你的排除項目進行檢查"
+ }
+ }
+ }
+ },
"Can’t be read as a property list, so nothing can read these settings." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
index 64bccc20..253ed8ca 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
@@ -151,7 +151,7 @@ public struct LeftoverScanner: Sendable {
}
return LeftoverScan(
leftovers: leftovers
- .map { exclusions.holds($0.url) ? $0.heldBack(.holdsAnExclusion) : $0 }
+ .map { leftover in exclusions.holdBack(for: leftover.url).map(leftover.heldBack) ?? leftover }
.sorted(by: Leftover.comesBefore),
unreadableLocations: unreadableLocations.sorted(by: byPath),
cutShortLocations: cutShortLocations.sorted(by: byPath),
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
index e4e30403..8c69cce2 100644
--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
@@ -166,6 +166,9 @@ public struct OrphanScanner: Sendable {
item.heldBack = .signInPlugIn
return (entry.identifier, item)
}
+ if item.leftAlone == nil, exclusions.holdBack(for: item.url) == .couldNotLookInside {
+ item.heldBack = .couldNotLookInside
+ }
return (entry.identifier, Self.holdingBack(item, beyond: reach))
}
let teams = Set(installedApps.compactMap(\.teamIdentifier))
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift
index d01ff6bf..b30e7246 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift
@@ -206,9 +206,11 @@ struct RemovalGuard: Sendable {
guard !exclusions.isAnExcludedApp(item ?? URL(filePath: path)) else { return .excluded }
var couldNotLookInside = false
for name in names {
- guard exclusions.appFolders(inside: URL(filePath: name, directoryHint: .isDirectory)).isEmpty else {
- return .excluded
+ // The helper knows nothing of the exclusions, so a folder that can't be looked into for one stays.
+ guard let excluded = exclusions.appFolders(inside: URL(filePath: name, directoryHint: .isDirectory)) else {
+ return .couldNotLookInside
}
+ guard excluded.isEmpty else { return .excluded }
// An uninstall lists a whole container, and the documents inside would go with it. Space lists a
// vendor's whole cache folder, and work kept only there (an IDE's local history) would go with it.
guard !ProtectedData.holdsAContainersDocuments(name) else { return .holdsDocuments }
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
index 0ead3656..dca04d93 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
@@ -133,7 +133,7 @@ public struct Uninstallation: Sendable {
root: environment.rootDirectory.path(percentEncoded: false)
)
.heldBack(managedBy.leftBehind)
- leftovers.append(exclusions.holds(url) ? leftover.heldBack(.holdsAnExclusion) : leftover)
+ leftovers.append(exclusions.holdBack(for: url).map(leftover.heldBack) ?? leftover)
}
}
return leftovers
@@ -215,7 +215,7 @@ public struct Uninstallation: Sendable {
home: home,
root: root
)
- var leftovers = [exclusions.holds(folder) ? leftover.heldBack(.holdsAnExclusion) : leftover]
+ var leftovers = [exclusions.holdBack(for: folder).map(leftover.heldBack) ?? leftover]
let receipt = PathPattern.comparablePath(of: folder)
for location in environment.locations where location.kind.isForLinks {
let links = HomebrewReceipt.links(in: location.url, leadingInto: receipt)
@@ -276,7 +276,7 @@ public struct Uninstallation: Sendable {
home: environment.homeDirectory.path(percentEncoded: false),
root: environment.rootDirectory.path(percentEncoded: false)
)
- leftovers.append(exclusions.holds(item.url) ? leftover.heldBack(.holdsAnExclusion) : leftover)
+ leftovers.append(exclusions.holdBack(for: item.url).map(leftover.heldBack) ?? leftover)
}
return leftovers
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift b/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
index 60b6875b..b5ca6da7 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
@@ -126,10 +126,27 @@ public struct Exclusions: Sendable, Codable, Hashable {
}
}
- /// True when something excluded sits inside `url`, so moving `url` would take it along.
+ /// True when something excluded is known to sit inside `url`, so moving `url` would take it along.
public func holds(_ url: URL) -> Bool {
+ holdsSomething(url) == true
+ }
+
+ /// Whether something excluded sits inside `url`, or nil when a folder inside can't be looked into for an excluded
+ /// app. It reads the disk.
+ func holdsSomething(_ url: URL) -> Bool? {
guard !spellings.isEmpty || !bundleIdentifiers.isEmpty else { return false }
- return holds(spellings: Self.spellings(of: url)) || !appFolders(inside: url).isEmpty
+ if holds(spellings: Self.spellings(of: url)) { return true }
+ return appFolders(inside: url).map { !$0.isEmpty }
+ }
+
+ /// Why an item stays for the exclusions: something excluded is inside, or a folder inside can't be looked into
+ /// for one, which only Peel can do, since the helper knows nothing of the exclusions.
+ func holdBack(for url: URL) -> HoldBack? {
+ switch holdsSomething(url) {
+ case true?: .holdsAnExclusion
+ case nil: .couldNotLookInside
+ case false?: nil
+ }
}
/// `holds(_:)` for a path whose spellings are already worked out.
@@ -140,20 +157,28 @@ public struct Exclusions: Sendable, Codable, Hashable {
}
}
- /// The excluded apps' folders, and the excluded apps themselves, a level or two inside `folder`. It reads the disk.
- func appFolders(inside folder: URL) -> [URL] {
+ /// The excluded apps' folders, and the excluded apps themselves, a level or two inside `folder`, or nil when a
+ /// folder there can't be listed. It reads the disk.
+ func appFolders(inside folder: URL) -> [URL]? {
guard !bundleIdentifiers.isEmpty else { return [] }
let list = { (folder: URL) in
- (try? FileManager.default.contentsOfDirectory(at: folder, includingPropertiesForKeys: nil)) ?? []
+ ProtectedData.names(in: folder.path(percentEncoded: false), followingLinks: false)?
+ .map { folder.appending(path: $0) }
}
let isExcluded = { (url: URL) in
appFolderNames.contains(url.lastPathComponent.lowercased()) || isAnExcludedApp(url)
}
- return list(folder).flatMap { child in
- if isExcluded(child) { return [child] }
- guard child.isRealFolder else { return [] }
- return list(child).filter(isExcluded)
+ guard let children = list(folder) else { return nil }
+ var found: [URL] = []
+ for child in children {
+ if isExcluded(child) {
+ found.append(child)
+ } else if child.isRealFolder {
+ guard let inside = list(child) else { return nil }
+ found += inside.filter(isExcluded)
+ }
}
+ return found
}
/// Whether `url` is an app whose own Info.plist declares an excluded identifier: its bundle is named for the app,
@@ -172,7 +197,7 @@ public struct Exclusions: Sendable, Codable, Hashable {
Self.spellings(of: path).map(PathComponents.of).contains { names in
asked.contains { names.count > $0.count && names.starts(with: $0) }
}
- } + appFolders(inside: url)
+ } + (appFolders(inside: url) ?? [])
return inside.filter { place in !inside.contains { $0 != place && Exclusions(paths: [$0]).excludes(place) } }
}
@@ -231,21 +256,30 @@ public struct Exclusions: Sendable, Codable, Hashable {
app.bundleIdentifier.map(excludes(bundleIdentifier:)) == true || excludes(app.url)
}
- /// True when `brew uninstall` would delete something excluded: an app the package installs (`apps` are the
- /// installed apps known to be its), an app identifier it quits, or its own folder under `prefix`. An
- /// unreadable list, or one not read yet, counts as excluding every package, since `brew uninstall` cannot be
- /// undone.
- public func excludes(_ package: HomebrewPackage, apps: [InstalledApp], prefix: URL?) -> Bool {
+ /// Whether `brew uninstall` would delete something excluded: an app the package installs (`apps` are the
+ /// installed apps known to be its), an app identifier it quits, or its own folder under `prefix`. Nil when one of
+ /// these can't be looked into for an excluded app. An unreadable list, or one not read yet, counts as excluding
+ /// every package, since `brew uninstall` cannot be undone.
+ public func excludes(_ package: HomebrewPackage, apps: [InstalledApp], prefix: URL?) -> Bool? {
guard isKnown else { return true }
- let targets = package.appTargets.map { URL(filePath: $0, directoryHint: .isDirectory) } + apps.map(\.url)
- if targets.contains(where: { excludes($0) || holds($0) }) { return true }
if apps.contains(where: { $0.bundleIdentifier.map(excludes(bundleIdentifier:)) == true }) { return true }
if package.quitIdentifiers.contains(where: { excludes(bundleIdentifier: $0) }) { return true }
- guard let prefix else { return false }
- let own = prefix
- .appending(path: package.kind == .cask ? "Caskroom" : "Cellar", directoryHint: .isDirectory)
- .appending(path: package.name, directoryHint: .isDirectory)
- return excludes(own) || holds(own)
+ let own = prefix.map {
+ $0.appending(path: package.kind == .cask ? "Caskroom" : "Cellar", directoryHint: .isDirectory)
+ .appending(path: package.name, directoryHint: .isDirectory)
+ }
+ let folders = package.appTargets.map { URL(filePath: $0, directoryHint: .isDirectory) } + apps.map(\.url)
+ + [own].compactMap(\.self)
+ var isKnownToHoldNothing = true
+ for folder in folders {
+ if excludes(folder) { return true }
+ switch holdsSomething(folder) {
+ case true?: return true
+ case nil: isKnownToHoldNothing = false
+ case false?: break
+ }
+ }
+ return isKnownToHoldNothing ? false : nil
}
/// The installed formulae whose own folder under `prefix` is excluded or holds something excluded, which
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift b/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift
index 36783fbf..c0b7b4ea 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift
@@ -332,7 +332,7 @@ public enum ProtectedData: Sendable {
case notKnown
}
- static func names(in folder: String, followingLinks: Bool) -> [String]? {
+ public static func names(in folder: String, followingLinks: Bool) -> [String]? {
listing(folder, followingLinks: followingLinks) { try FileManager.default.contentsOfDirectory(atPath: $0) }
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift
index ec0f474d..78f3f4e9 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift
@@ -933,4 +933,28 @@ struct AttackRemovalGuardTests {
#expect(ProtectedData.holdsABrowserWallet(path("Profiles")) == .notKnown)
#expect(ProtectedData.holdsABrowserWallet(path("Missing")) == .nothing)
}
+
+ /// The helper knows nothing of the exclusions, so a folder Peel can't search for them stays, even one only the
+ /// helper could move.
+ @Test(.permissionsHold) func aFolderItCannotSearchForAnExclusionStaysWhoeverWouldMoveIt() throws {
+ let directory = try TemporaryDirectory()
+ let vendor = "root/Library/Application Support/org.example.Vendor"
+ try directory.file(vendor + "/kept/org.example.excluded/state.db")
+ try directory.setPermissions(0, of: vendor + "/kept")
+ try directory.setPermissions(0o555, of: vendor)
+ defer {
+ try? directory.setPermissions(0o755, of: vendor)
+ try? directory.setPermissions(0o755, of: vendor + "/kept")
+ }
+ let environment = SearchEnvironment(
+ homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),
+ rootDirectory: directory.url.appending(path: "root", directoryHint: .isDirectory)
+ )
+ let url = directory.url.appending(path: vendor, directoryHint: .isDirectory)
+ let excluding = RemovalGuard(environment: environment, exclusions: Exclusions(bundleIdentifiers: ["org.example.excluded"]))
+
+ #expect(FileAccess.requiresPrivilegesToRemove(url))
+ #expect(excluding.refusal(of: url) == .couldNotLookInside)
+ #expect(RemovalGuard(environment: environment).refusal(of: url) == nil, "with no app excluded, the helper looks")
+ }
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift
index b3846b84..a50e53d2 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift
@@ -92,19 +92,31 @@ struct ExclusionsTests {
let cask = HomebrewPackage(name: "example", kind: .cask, appTargets: ["/Applications/Example.app"], quitIdentifiers: ["com.example.app"])
let formula = HomebrewPackage(name: "wget", kind: .formula)
- #expect(Exclusions(paths: [URL(filePath: "/Applications/Example.app")]).excludes(cask, apps: [], prefix: prefix))
- #expect(Exclusions(paths: [URL(filePath: "/Applications/Example.app/Contents/Resources/keep")]).excludes(cask, apps: [], prefix: prefix))
- #expect(Exclusions(bundleIdentifiers: ["com.example.app"]).excludes(cask, apps: [app], prefix: prefix))
- #expect(Exclusions(bundleIdentifiers: ["com.example.app"]).excludes(cask, apps: [], prefix: prefix), "the identifier it quits names it too")
- #expect(Exclusions(paths: [URL(filePath: "/opt/homebrew/Caskroom/example")]).excludes(cask, apps: [], prefix: prefix))
- #expect(Exclusions(paths: [URL(filePath: "/opt/homebrew")]).excludes(formula, apps: [], prefix: prefix))
- #expect(Exclusions.unreadable.excludes(formula, apps: [], prefix: prefix), "a list that cannot be read keeps everything")
- #expect(Exclusions.notYetRead.excludes(formula, apps: [], prefix: prefix), "a list not read yet keeps everything")
+ #expect(Exclusions(paths: [URL(filePath: "/Applications/Example.app")]).excludes(cask, apps: [], prefix: prefix) == true)
+ #expect(Exclusions(paths: [URL(filePath: "/Applications/Example.app/Contents/Resources/keep")]).excludes(cask, apps: [], prefix: prefix) == true)
+ #expect(Exclusions(bundleIdentifiers: ["com.example.app"]).excludes(cask, apps: [app], prefix: prefix) == true)
+ #expect(Exclusions(bundleIdentifiers: ["com.example.app"]).excludes(cask, apps: [], prefix: prefix) == true, "the identifier it quits names it too")
+ #expect(Exclusions(paths: [URL(filePath: "/opt/homebrew/Caskroom/example")]).excludes(cask, apps: [], prefix: prefix) == true)
+ #expect(Exclusions(paths: [URL(filePath: "/opt/homebrew")]).excludes(formula, apps: [], prefix: prefix) == true)
+ #expect(Exclusions.unreadable.excludes(formula, apps: [], prefix: prefix) == true, "a list that cannot be read keeps everything")
+ #expect(Exclusions.notYetRead.excludes(formula, apps: [], prefix: prefix) == true, "a list not read yet keeps everything")
let unrelated = Exclusions(paths: [URL(filePath: "/Applications/Other.app")], bundleIdentifiers: ["com.other.app"])
- #expect(!unrelated.excludes(cask, apps: [app], prefix: prefix))
- #expect(!unrelated.excludes(formula, apps: [], prefix: prefix))
- #expect(!Exclusions(paths: [URL(filePath: "/opt/homebrew/Cellar/curl")]).excludes(formula, apps: [], prefix: prefix))
+ #expect(unrelated.excludes(cask, apps: [app], prefix: prefix) == false)
+ #expect(unrelated.excludes(formula, apps: [], prefix: prefix) == false)
+ #expect(Exclusions(paths: [URL(filePath: "/opt/homebrew/Cellar/curl")]).excludes(formula, apps: [], prefix: prefix) == false)
+ }
+
+ /// A folder Peel can't look inside may hold what an excluded app keeps, so `brew uninstall` isn't run on it.
+ @Test(.permissionsHold) func keepsAPackageItCannotSearchForAnExclusion() throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("prefix/Caskroom/example/1.0/kept/org.example.excluded/state.db")
+ try directory.setPermissions(0, of: "prefix/Caskroom/example/1.0")
+ defer { try? directory.setPermissions(0o755, of: "prefix/Caskroom/example/1.0") }
+ let prefix = directory.url.appending(path: "prefix", directoryHint: .isDirectory)
+ let cask = HomebrewPackage(name: "example", kind: .cask)
+
+ #expect(Exclusions(bundleIdentifiers: ["org.example.excluded"]).excludes(cask, apps: [], prefix: prefix) == nil)
}
@Test func matchesAppsByBundleIdentifierOrPlace() {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
index 7ebdbb72..73ac5e51 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
@@ -1117,6 +1117,28 @@ struct LeftoverScannerTests {
#expect(!found.isMeasured, "a folder nobody measured was given a size of zero")
}
+ /// The helper knows nothing of the exclusions, so a folder Peel can't search for them is left alone, even one
+ /// only the helper could move.
+ @Test(.permissionsHold) func leavesAloneAFolderItCannotSearchForAnExclusion() async throws {
+ let directory = try TemporaryDirectory()
+ let place = "root/Library/Application Support/Tunewell"
+ try directory.file(place + "/kept/org.example.excluded/state.db")
+ try directory.setPermissions(0, of: place + "/kept")
+ try directory.setPermissions(0o555, of: place)
+ defer {
+ try? directory.setPermissions(0o755, of: place)
+ try? directory.setPermissions(0o755, of: place + "/kept")
+ }
+ let exclusions = Exclusions(bundleIdentifiers: ["org.example.excluded"])
+
+ let scanner = LeftoverScanner(environment: environment(in: directory), exclusions: exclusions)
+ let scan = await scanner.scan(tunewell, installedApps: [tunewell])
+
+ let found = try #require(scan.leftovers.first { $0.url.lastPathComponent == "Tunewell" })
+ #expect(found.requiresPrivileges)
+ #expect(found.match.heldBack == .couldNotLookInside)
+ }
+
@Test func measuresNothingExcluded() async throws {
let directory = try TemporaryDirectory()
try directory.file("home/Library/Caches/net.example.client/cache.db")
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
index 39bb18fa..c8f01bed 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
@@ -573,6 +573,33 @@ struct OrphanScannerTests {
#expect(item.size == nil)
}
+ /// The helper knows nothing of the exclusions, so a folder Peel can't search for them is left alone, even one
+ /// only the helper could move.
+ @Test(.permissionsHold) func leavesAloneAFolderItCannotSearchForAnExclusion() async throws {
+ let directory = try TemporaryDirectory()
+ let place = "root/Library/Application Support/com.gone.app"
+ try directory.file(place + "/kept/org.example.excluded/state.db")
+ try directory.setPermissions(0, of: place + "/kept")
+ try directory.setPermissions(0o555, of: place)
+ defer {
+ try? directory.setPermissions(0o755, of: place)
+ try? directory.setPermissions(0o755, of: place + "/kept")
+ }
+ let environment = SearchEnvironment(
+ homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),
+ rootDirectory: directory.url.appending(path: "root", directoryHint: .isDirectory)
+ )
+ let scanner = OrphanScanner(
+ environment: environment, exclusions: Exclusions(bundleIdentifiers: ["org.example.excluded"]),
+ isRegisteredApp: { _ in false }
+ )
+
+ let item = try #require(await scanner.scan(installedApps: installed).groups.first?.items.first)
+
+ #expect(item.requiresPrivileges)
+ #expect(item.heldBack == .couldNotLookInside)
+ }
+
/// A reason that keeps a folder where it is outranks what the walk saw, which only leaves it to be chosen.
@Test func whatKeepsAFolderInPlaceOutranksWhatTheWalkSaw() async throws {
let directory = try TemporaryDirectory()
diff --git a/Peel/Views/Homebrew/HomebrewDetailView.swift b/Peel/Views/Homebrew/HomebrewDetailView.swift
index 4e1276aa..c386a48f 100644
--- a/Peel/Views/Homebrew/HomebrewDetailView.swift
+++ b/Peel/Views/Homebrew/HomebrewDetailView.swift
@@ -235,7 +235,11 @@ struct HomebrewDetailView: View {
guard let extensionsAnswer, extensionsAnswer.apps == carrying else { return "Checking…" }
if let removedElsewhere = extensionsAnswer.removedElsewhere { return removedElsewhere.explanation }
}
- return exclusions.exclusions.excludes(package, apps: apps, prefix: homebrew.installation?.prefix) ? "Excluded in Settings" : nil
+ switch exclusions.exclusions.excludes(package, apps: apps, prefix: homebrew.installation?.prefix) {
+ case true?: return "Excluded in Settings"
+ case nil: return "Can’t be checked against your exclusions"
+ case false?: return nil
+ }
}
private var caskApps: [InstalledApp] {
diff --git a/SAFETY.md b/SAFETY.md
index 98298649..91010d3f 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -522,12 +522,15 @@ the other tools leave it out. An excluded app still appears in Applications, so
removal plan and no reset, in the app and in `peel`, and nothing moves it to the Trash or puts it back, from any
page and whatever its bundle is called, nor a folder that holds it a level or two down. A folder named with its
identifier, such as its caches or its container, is left out of every page and never moved, nor is a folder holding
-one a level or two down. Its other files, such as plug-ins, receipts, or a folder named after the app, are excluded
+one a level or two down, nor one with a folder inside that macOS won't let Peel list, since such a folder may be in
+there: that holds even for what only the helper could move, as the helper knows nothing of your exclusions. Its other
+files, such as plug-ins, receipts, or a folder named after the app, are excluded
only by their own paths, so to keep them, exclude them too.
Exclusions reach the Homebrew page too, since Homebrew deletes for good: Peel never runs `brew uninstall` for a
-package whose app, or whose own folder, you excluded, nor for any package while your list isn't read or can't be,
-and Homebrew's cleanup keeps every formula whose folder you excluded.
+package whose app, or whose own folder, you excluded, nor for one with a folder Peel can't look into for an app you
+excluded, nor for any package while your list isn't read or can't be, and Homebrew's cleanup keeps every formula whose
+folder you excluded.
If the saved list is there and cannot be read, Peel does not treat it as empty. It moves nothing until you
start over in Settings, `peel` refuses, and the file it could not read is kept beside the new one.