Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Read a job's signature only when its program is gone
Țugui Dragoșe3410c829d0f
diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swiftindex 780c0c94..7668f353 100644--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swift+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swift@@ -97,6 +97,8 @@ public struct BackgroundItemOwnership: Sendable {/// Runs the same check on a job read from its property list. Orphaned Files uses this one.func isOrphan(_ job: JobDefinition) -> Bool {+ // A program still on disk keeps its job whoever owns it, so the owner, which reads signatures, is not needed.+ if let program = job.program, !program.isEmpty, Self.exists(program) { return false }let owner = owner(label: job.label, associated: job.associated, program: job.program)return isOrphan(label: job.label, program: job.program, owner: owner)}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemOwnershipTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemOwnershipTests.swiftindex ac0c16ef..3dff6701 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemOwnershipTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemOwnershipTests.swift@@ -1,6 +1,7 @@import Foundation@testable import PeelCoreimport PeelPrivileged+import Synchronizationimport Testingstruct BackgroundItemOwnershipTests {@@ -18,6 +19,21 @@ struct BackgroundItemOwnershipTests {)}+ @Test func readsAJobsSignatureOnlyWhenItsProgramIsGone() throws {+ final class Reads: Sendable { let programs = Mutex<[String]>([]) }+ let reads = Reads()+ let ownership = BackgroundItemOwnership(installedApps: []) { program in+ reads.programs.withLock { $0.append(program) }+ return nil+ }+ let live = try #require(JobDefinition(["Label": "org.example.live", "Program": "/bin/sh"]))+ let gone = try #require(JobDefinition(["Label": "org.example.gone", "Program": "/opt/org.example/gone"]))++ #expect(!ownership.isOrphan(live))+ #expect(ownership.isOrphan(gone))+ #expect(reads.programs.withLock { $0 } == ["/opt/org.example/gone"])+ }+/// What the helper refuses, the page must not offer: both read the same label.@Test func knowsTheJobTheHelperWillNotActOn() {func item(_ label: String, _ kind: BackgroundItem.Kind) -> BackgroundItem {