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
An extension list Peel cannot read is not an empty one
Țugui Dragoș736107b5bb26
diff --git a/Packages/PeelCore/Sources/PeelCore/Extensions/AppExtensions.swift b/Packages/PeelCore/Sources/PeelCore/Extensions/AppExtensions.swiftindex 200a0722..41bbfc5a 100644--- a/Packages/PeelCore/Sources/PeelCore/Extensions/AppExtensions.swift+++ b/Packages/PeelCore/Sources/PeelCore/Extensions/AppExtensions.swift@@ -125,10 +125,16 @@ public enum AppExtensions {)}+ /// Returns what apps added, or nil when `pluginkit` gave no answer Peel can read. It always lists macOS's own+ /// extensions and ends by counting what it listed, so a listing read short of that is not understood.static func appExtensions(run: Runner) async -> [AppExtension]? {guard let output = await run("/usr/bin/pluginkit", ["-m", "-v"]) else { return nil }- return output.split(whereSeparator: \.isNewline).compactMap { line in- guard let parsed = parse(String(line)), !isTheSystemsOwn(parsed.path) else { return nil }+ let lines = output.split(whereSeparator: \.isNewline)+ let rows = lines.compactMap { parse(String($0)) }+ let listed = count(in: lines, /^ *\((\d+) plug-ins?\)$/)+ guard !rows.isEmpty, listed == nil || listed == rows.count else { return nil }+ return rows.compactMap { parsed in+ guard !isTheSystemsOwn(parsed.path) else { return nil }let url = URL(filePath: parsed.path, directoryHint: .isDirectory)let info = AppInspector.infoDictionary(in: url.appending(path: "Contents", directoryHint: .isDirectory))return AppExtension(@@ -231,11 +237,15 @@ public enum AppExtensions {return AppInspector.displayName(of: URL(filePath: String(path[..<end.lowerBound]) + ".app"))}+ /// Returns the system extensions, or nil when `systemextensionsctl` gave no answer Peel can read: its first+ /// line counts the rows that follow, and a listing read short of it is not understood.static func systemExtensions(run: Runner) async -> [AppExtension]? {guard let output = await run("/usr/bin/systemextensionsctl", ["list"]) else { return nil }+ let lines = output.split(whereSeparator: \.isNewline)+ let rows = lines.compactMap { parseSystemExtension(String($0)) }+ guard count(in: lines, /^(\d+) extension\(s\)$/) == rows.count else { return nil }let records = systemExtensionRecords()- return output.split(whereSeparator: \.isNewline).compactMap { line in- guard let row = parseSystemExtension(String(line)) else { return nil }+ return rows.map { row inlet record = record(for: row.identifier, version: row.version, among: records)return AppExtension(// During an update, one identifier is listed twice, once for the old version and once for the new.@@ -253,6 +263,11 @@ public enum AppExtensions {}}+ /// The number a tool's line of summary gives, or nil when no line reads that way.+ private static func count(in lines: [Substring], _ summary: Regex<(Substring, Substring)>) -> Int? {+ lines.lazy.compactMap { try? summary.wholeMatch(in: $0) }.first.flatMap { Int($0.1) }+ }+/// Parses one row of `systemextensionsctl list`, laid out as/// `<enabled>\t<active>\t<team>\t<identifier> (<version>)\t<name>\t[<state>]`. The header row above each/// category has the same columns and is skipped, since its identifier column (`bundleID`) has no dot.diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppExtensionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppExtensionsTests.swiftindex 7b237256..931caeb5 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/AppExtensionsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppExtensionsTests.swift@@ -220,18 +220,48 @@ struct AppExtensionsTests {/// Each kind comes from its own tool, so a tool that gives no answer leaves out its own kind and nothing/// else, and the scan says which kind is missing: what it lists is then only part of what is installed.@Test func saysWhichKindMacOSGaveNoAnswerAbout() async {- let noSystemExtensions: AppExtensions.Runner = { tool, _ in tool.hasSuffix("/pluginkit") ? "" : nil }- let noAppExtensions: AppExtensions.Runner = { tool, _ in tool.hasSuffix("/systemextensionsctl") ? "" : nil }+ let none = "0 extension(s)"+ let appsOnly: AppExtensions.Runner = { tool, _ in tool.hasSuffix("/pluginkit") ? Self.pluginkit : nil }+ let systemOnly: AppExtensions.Runner = { tool, _ in tool.hasSuffix("/systemextensionsctl") ? none : nil }+ let both: AppExtensions.Runner = { tool, _ in tool.hasSuffix("/pluginkit") ? Self.pluginkit : none }- #expect(await AppExtensions.scan(exclusions: .none, run: noSystemExtensions).unanswered == [.systemExtension])- #expect(await AppExtensions.scan(exclusions: .none, run: noAppExtensions).unanswered == [.appExtension])+ #expect(await AppExtensions.scan(exclusions: .none, run: appsOnly).unanswered == [.systemExtension])+ #expect(await AppExtensions.scan(exclusions: .none, run: systemOnly).unanswered == [.appExtension])#expect(await AppExtensions.scan(exclusions: .none, run: { _, _ in nil }).unanswered == Set(AppExtension.Kind.allCases))- #expect(await AppExtensions.scan(exclusions: .none, run: { _, _ in "" }).unanswered.isEmpty)+ #expect(await AppExtensions.scan(exclusions: .none, run: both).unanswered.isEmpty)+ }++ private static let pluginkit = """+ com.apple.example.Sample(1.0)\t6299ACC7-6EDA-4A38-9BD4-89444C604682\t2026-09-20 17:23:02 +0000\t\+ /System/Library/Sample.appex+ (1 plug-in)+ """++ /// `pluginkit` always lists macOS's own extensions and ends by counting them, and `systemextensionsctl` starts+ /// by counting its rows. A listing read short of its count is one Peel no longer understands, not a Mac with none.+ @Test func aListingReadShortOfItsCountIsNoAnswer() async {+ let rows = """+ 2 extension(s)+ enabled\tactive\tteamID\tbundleID (version)\tname\t[state]+ *\t*\tTC3Q7MAJXF\torg.example.filter (1.0/100)\tExample Filter\t[activated enabled]+ """+ let spaced = Self.pluginkit.replacing("\t", with: " ")++ #expect(await AppExtensions.appExtensions { _, _ in Self.pluginkit } == [])+ #expect(await AppExtensions.appExtensions { _, _ in spaced } == nil)+ #expect(await AppExtensions.appExtensions { _, _ in "" } == nil)+ #expect(await AppExtensions.systemExtensions { _, _ in "0 extension(s)" } == [])+ #expect(await AppExtensions.systemExtensions { _, _ in rows } == nil)+ let one = rows.replacing("2 extension(s)", with: "1 extension(s)")+ #expect(await AppExtensions.systemExtensions { _, _ in one }?.count == 1)+ #expect(await AppExtensions.systemExtensions { _, _ in "" } == nil)}/// Scans the Mac the test runs on. The scan only reads, so the test runs every time.@Test func readsThisMacWithoutTouchingIt() async {- let found = await AppExtensions.scan().extensions+ let scan = await AppExtensions.scan()+ let found = scan.extensions+ #expect(scan.unanswered.isEmpty, "this Mac's listing was not read whole")#expect(found.allSatisfy { $0.url.map { !AppExtensions.isTheSystemsOwn($0.path(percentEncoded: false)) } ?? true })#expect(Set(found.map(\.id)).count == found.count, "the same extension was listed twice")}