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.

Reset no privacy permissions for an app a lock keeps in place

Țugui Dragoș5fb6655eefdb
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
index 9bf2a5a0..2808f01f 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
@@ -387,9 +387,9 @@ public struct TrashService: Sendable {
return historyRefusal
}
- /// Why each of `apps` would not move now in an uninstall, by the checks its move makes: the guard, History, and
- /// the programs holding it, unless only the app's own background programs do, which the move stops first. An app
- /// missing from the answer would move.
+ /// Why each of `apps` would not move now in an uninstall, by the checks its move makes: the guard, History, a lock
+ /// on the bundle, which nobody can rename, root included, and the programs holding it, unless only the app's own
+ /// background programs do, which the move stops first. An app missing from the answer would move.
func refusalsNow(
ofApps apps: [URL],
lettingTheirProgramsRun running: Set<URL>
@@ -401,6 +401,10 @@ public struct TrashService: Sendable {
refusals[app] = refusal
continue
}
+ if FileAccess.isLocked(app) {
+ refusals[app] = FileAccess.isLockedInFinder(app) ? .locked : .notPermitted
+ continue
+ }
let mayRun = running.contains(app)
guard let held = openFiles.refusal(of: app, lettingItsProgramsRun: mayRun) else { continue }
if held.isHeldByPrograms, await jobsHoldingOnly(app, in: openFiles, lettingItsProgramsRun: mayRun) != nil {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift
index cdbc4c0f..06be278a 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift
@@ -747,6 +747,17 @@ struct PrivacyResetTests {
#expect(await PrivacyReset.goingNow([held, free], with: service(in: directory)).map(\.bundleIdentifier) == ["org.example.free"])
}
+ @Test func resetsNoAppALockKeepsInPlace() async throws {
+ let directory = try TemporaryDirectory()
+ let url = try directory.directory("Applications/Locked.app")
+ let locked = InstalledApp(url: url, bundleIdentifier: "org.example.locked", name: "Locked")
+ #expect(chflags(url.path(percentEncoded: false), UInt32(UF_IMMUTABLE)) == 0)
+ defer { chflags(url.path(percentEncoded: false), 0) }
+
+ #expect(await PrivacyReset.goingNow([locked], with: service(in: directory)).isEmpty)
+ #expect(await service(in: directory).refusalsNow(ofApps: [url], lettingTheirProgramsRun: []) == [url: .locked])
+ }
+
private func service(in directory: borrowing TemporaryDirectory) -> TrashService {
TrashService(environment: SearchEnvironment(
homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),