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 an app installed while Peel can't read where it is

Țugui Dragoș612e5a8580da
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppMemory.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppMemory.swift
index 12e7eb9e..2e615f67 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppMemory.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppMemory.swift
@@ -15,15 +15,18 @@ public struct RememberedApp: Sendable, Hashable, Codable, Identifiable {
}
extension RememberedApp {
- /// The app as it is now, when Peel cannot tell that it left: its bundle is still where Peel last saw it, or the
- /// disk it was on is not connected. Nil once the place can be looked at and the app is not there.
+ /// The app as it is now, when Peel cannot tell that it left: its bundle is still where Peel last saw it, the disk
+ /// it was on is not connected, or macOS will not let Peel read its Info.plist. Nil once the place can be looked at
+ /// and the app is not there.
func stillInstalled() -> InstalledApp? {
let place = URL(filePath: lastPath, directoryHint: .isDirectory)
if let app = AppInspector.inspect(place), app.bundleIdentifier == bundleIdentifier { return app }
let names = PathComponents.of(lastPath)
- guard names.count > 2, names[0] == "Volumes", URL(filePath: "/Volumes/\(names[1])").isMissing else {
- return nil
- }
+ let isOnADiskNotConnected = names.count > 2 && names[0] == "Volumes"
+ && URL(filePath: "/Volumes/\(names[1])").isMissing
+ let info = place.appending(path: "Contents/Info.plist")
+ let isClosedToPeel = !info.isMissing && BoundedRead.data(at: info) == nil
+ guard isOnADiskNotConnected || isClosedToPeel else { return nil }
return InstalledApp(url: place, bundleIdentifier: bundleIdentifier, name: name, teamIdentifier: teamIdentifier)
}
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
index e1237a65..3d3e9386 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
@@ -552,6 +552,46 @@ struct OrphanScannerTests {
#expect(scan.groups.map(\.identifier) == ["org.example-gone.app"])
}
+ @Test(.permissionsHold) func anAppInAPlacePeelCannotReadHasNotLeft() async throws {
+ let directory = try TemporaryDirectory()
+ var remembered: [RememberedApp] = []
+ for name in ["Closed", "Sealed"] {
+ let identifier = "org.example-\(name.lowercased()).app"
+ let info = """
+ <?xml version="1.0" encoding="UTF-8"?>
+ <plist version="1.0"><dict><key>CFBundleIdentifier</key><string>\(identifier)</string></dict></plist>
+ """
+ let app = try directory.file("\(name)/\(name).app/Contents/Info.plist", contents: Data(info.utf8))
+ .deletingLastPathComponent().deletingLastPathComponent()
+ try directory.file("home/Library/Caches/\(identifier)/cache.db")
+ remembered.append(RememberedApp(
+ bundleIdentifier: identifier,
+ name: name,
+ teamIdentifier: nil,
+ lastSeen: .now,
+ lastPath: app.path(percentEncoded: false)
+ ))
+ }
+ try directory.file("home/Library/Caches/org.example-gone.app/cache.db")
+ remembered.append(RememberedApp(
+ bundleIdentifier: "org.example-gone.app",
+ name: "Gone",
+ teamIdentifier: nil,
+ lastSeen: .now,
+ lastPath: try directory.directory("Open").appending(path: "Gone.app").path(percentEncoded: false)
+ ))
+ try directory.setPermissions(0o000, of: "Closed")
+ try directory.setPermissions(0o000, of: "Sealed/Sealed.app/Contents/Info.plist")
+ defer {
+ try? directory.setPermissions(0o755, of: "Closed")
+ try? directory.setPermissions(0o644, of: "Sealed/Sealed.app/Contents/Info.plist")
+ }
+
+ let scan = await scanner(in: directory).scan(installedApps: installed, remembered: remembered)
+
+ #expect(scan.groups.map(\.identifier) == ["org.example-gone.app"])
+ }
+
/// What an item declares about itself is asked of the installed apps as its name is: a maker's plug-in, named for
/// what it does, and a container named by a UUID for an extension an installed app embeds are that app's.
@Test func anItemsDeclaredIdentifierIsAskedOfTheInstalledApps() async throws {