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
Never judge a launchd job by a program path that holds a NUL
Țugui Dragoș4e59543a213a
diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swiftindex 7668f353..543ce0f9 100644--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swift+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swift@@ -92,6 +92,8 @@ public struct BackgroundItemOwnership: Sendable {guard !label.hasPrefix("com.apple."), !label.hasPrefix("application.") else { return false }if let owner, owner.isInstalled { return false }guard let program, !program.isEmpty else { return true }+ // A NUL ends the path where the kernel reads it, so what launchd would run is not known.+ guard !program.utf8.contains(0) else { return false }return !Self.exists(program)}diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swiftindex fb86b0a8..809f5d75 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift@@ -140,7 +140,8 @@ struct LeftoverMatcher: Sendable {/// The absolute program the launchd job at `url` runs, spelled to be compared, or nil for anything else.static func program(ofJobAt url: URL, kind: SearchLocation.Kind) -> String? {guard kind == .launchAgents || kind == .launchDaemons, url.pathExtension == "plist" else { return nil }- guard let program = JobDefinition(contentsOf: url)?.program, program.hasPrefix("/") else { return nil }+ guard let program = JobDefinition(contentsOf: url)?.program, program.hasPrefix("/"), !program.utf8.contains(0)+ else { return nil }return PathPattern.comparablePath(of: URL(filePath: program))}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemOwnershipTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemOwnershipTests.swiftindex 3dff6701..bd43a88e 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemOwnershipTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemOwnershipTests.swift@@ -34,6 +34,14 @@ struct BackgroundItemOwnershipTests {#expect(reads.programs.withLock { $0 } == ["/opt/org.example/gone"])}+ @Test func neverCallsGoneAProgramWhosePathHoldsANul() throws {+ let ownership = BackgroundItemOwnership(installedApps: []) { _ in nil }+ let job = try #require(JobDefinition(["Label": "org.example.cut", "Program": "/bin/sh\u{0}gone"]))++ #expect(!ownership.isOrphan(job))+ #expect(!ownership.isOrphan(label: "org.example.cut", program: "/bin/sh\u{0}gone", owner: nil))+ }+/// 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 {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swiftindex c0113afc..c9c01a37 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift@@ -1361,6 +1361,22 @@ struct LeftoverScannerTests {#expect(found["net.example.nagger.plist"]?.reason == .launchdJob)}+ @Test func neverClaimsAJobByAProgramPathWithANul() async throws {+ let directory = try TemporaryDirectory()+ let program = "/Applications/Other.app/Contents/MacOS/Agent\u{0}/../../../../Tunewell.app/Contents/MacOS/Agent"+ let plist = try PropertyListSerialization.data(+ fromPropertyList: ["Label": "com.elsewhere.agent", "Program": program], format: .binary, options: 0+ )+ try directory.file("home/Library/LaunchAgents/com.elsewhere.agent.plist", contents: plist)++ let scan = await LeftoverScanner(environment: environment(in: directory)).scan(+ tunewell,+ installedApps: [tunewell]+ )++ #expect(scan.leftovers.isEmpty)+ }+/// A link in `/usr/local/bin` or `/usr/local/sbin` is named for the tool it runs, such as `docker` or `code`,/// which says nothing about whose it is. Where it leads does.@Test func findsALinkToAToolInsideTheApp() async throws {