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.

Orphaned Files never lists what the guard refuses

Țugui Dragoș9220c017f8db
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
index 58fc8c29..d05590cd 100644
--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
@@ -291,6 +291,8 @@ public struct OrphanScanner: Sendable {
guard !Task.isCancelled else { break }
let url = location.url.appending(path: name)
guard isAFileAFolderOrALink(url) else { continue }
+ // What the guard refuses outright is never listed, whether an installed app claims it or not.
+ guard !ProtectedData.refuses(url.path(percentEncoded: false), home: home) else { continue }
guard let identifier = await orphanIdentifier(of: url, kind: location.kind, ownership: ownership, jobs: jobs, goneBundles: goneBundles) else { continue }
guard location.kind != .plugIns || cameWithAnAppThatLeft(identifier, goneApps: goneApps) else { continue }
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AttackScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AttackScannerTests.swift
index 8bbaf31d..e59f806b 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AttackScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AttackScannerTests.swift
@@ -96,6 +96,19 @@ struct AttackScannerTests {
#expect(found == ["com.gone.app"], "ATTACK SUCCEEDED: something of the user's own is reported as an orphan: \(found)")
}
+ /// Shortcuts keeps its data in a group container whose name has no `com.apple.` in it. Orphaned Files leaves it
+ /// out because the guard refuses it, not because the Shortcuts app happens to claim it: here nothing does.
+ @Test func orphanScannerNeverListsWhatTheGuardRefuses() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("home/Library/Group Containers/group.is.workflow.shortcuts/Shortcuts.sqlite")
+ try directory.file("home/Library/Group Containers/group.com.gone.app/data.db")
+ let scanner = OrphanScanner(environment: environment(directory), isRegisteredApp: { _ in false }, systemApps: [])
+
+ let found = await scanner.scan(installedApps: []).groups.map(\.identifier)
+
+ #expect(found == ["com.gone.app"], "ATTACK SUCCEEDED: what the guard refuses is listed as an orphan: \(found)")
+ }
+
/// There are real apps called Documents, Downloads, and Public. The folders every account starts with are
/// never theirs.
@Test func neverClaimsTheFoldersEveryAccountStartsWith() async throws {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
index 0c7c0725..37acd1d5 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
@@ -298,15 +298,15 @@ struct OrphanScannerTests {
/// The apps macOS ships claim their folders like any other app, and none of them is in the list Peel scans.
@Test func ignoresGroupsDeclaredBySystemApps() async throws {
let directory = try TemporaryDirectory()
- try directory.directory("home/Library/Group Containers/group.is.workflow.shortcuts")
- let shortcuts = InstalledApp(
- url: URL(filePath: "/System/Applications/Shortcuts.app"),
- bundleIdentifier: "is.workflow.my.app",
- name: "Shortcuts",
- applicationGroups: ["group.is.workflow.shortcuts"]
+ try directory.directory("home/Library/Group Containers/group.net.example.shared")
+ let systemApp = InstalledApp(
+ url: URL(filePath: "/System/Applications/Example.app"),
+ bundleIdentifier: "org.example.system",
+ name: "Example",
+ applicationGroups: ["group.net.example.shared"]
)
- #expect(await scanner(in: directory, systemApps: [shortcuts]).scan(installedApps: installed).groups.isEmpty)
+ #expect(await scanner(in: directory, systemApps: [systemApp]).scan(installedApps: installed).groups.isEmpty)
#expect(await !scanner(in: directory).scan(installedApps: installed).groups.isEmpty, "with no rival it is nobody's")
}