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.

Uninstalling lists an app's kernel extension, never selected

Țugui Dragoș35d8302be894
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
index 947c1ef2..7e88379d 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
@@ -140,7 +140,7 @@ struct LeftoverMatcher: Sendable {
private static let plugInExtensions = [
".component", ".vst3", ".vst", ".clap", ".driver", ".plugin", ".webplugin", ".bundle", ".mailbundle",
".prefPane", ".qlgenerator", ".saver", ".qtz", ".mdimporter", ".service", ".workflow", ".colorPicker",
- ".menu", ".inputmethod", ".app", ".aaxplugin", ".dictionary", ".action",
+ ".menu", ".inputmethod", ".app", ".aaxplugin", ".dictionary", ".action", ".kext",
]
static func withoutPlugInExtension(_ fileName: String) -> String {
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/SearchLocation.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/SearchLocation.swift
index f4bb9cc2..92af01c7 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/SearchLocation.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/SearchLocation.swift
@@ -125,11 +125,15 @@ public struct SearchEnvironment: Sendable {
/// The first folder of every Library path scanned as a location of its own, such as `Preferences`. The top of
/// a Library never offers one of these whole: they are looked inside, never moved.
static let libraryEntriesScannedElsewhere = Set(
- ((userEntries + localEntries).map(\.1) + Plugins.folders.map(\.0)).map { name in
+ ((userEntries + localEntries).map(\.1) + Plugins.folders.map(\.0) + [kernelExtensions]).map { name in
String(name.prefix { $0 != "/" })
}
)
+ /// Where a driver's kernel extensions stay in `/Library`. They are searched like plug-ins, named for what they
+ /// do, but the helper does not serve this folder, so what is found there is listed and never moved.
+ static let kernelExtensions = "Extensions"
+
public var locations: [SearchLocation] {
let userLibrary = homeDirectory.appending(path: "Library", directoryHint: .isDirectory)
let localLibrary = rootDirectory.appending(path: "Library", directoryHint: .isDirectory)
@@ -140,6 +144,9 @@ public struct SearchEnvironment: Sendable {
locations += [userLibrary, localLibrary].flatMap { library in
Plugins.folders.map { SearchLocation(kind: .plugIns, url: library.appending(path: $0.0, directoryHint: .isDirectory)) }
}
+ locations.append(SearchLocation(
+ kind: .plugIns, url: localLibrary.appending(path: Self.kernelExtensions, directoryHint: .isDirectory)
+ ))
if let userCacheDirectory {
locations.append(SearchLocation(kind: .caches, url: userCacheDirectory))
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
index 9d2f49f1..64d0ca30 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
@@ -919,6 +919,32 @@ struct LeftoverScannerTests {
#expect(found["home/Library/Example Audio/org.example.hexachord"]?.match.isRecommended == true)
}
+ /// A kernel extension an app's driver installed stays in `/Library/Extensions` after the app goes. It is found by
+ /// the identifier it declares and listed, but only an administrator can move it and Peel's helper does not serve
+ /// that folder, so it can never be selected.
+ @Test(.permissionsHold) func listsTheAppsKernelExtensionWithoutEverSelectingIt() async throws {
+ let directory = try TemporaryDirectory()
+ let app = InstalledApp(
+ url: URL(filePath: "/Applications/Hexachord.app"),
+ bundleIdentifier: "org.example.hexachord",
+ name: "Hexachord"
+ )
+ let info = try PropertyListSerialization.data(
+ fromPropertyList: ["CFBundleIdentifier": "org.example.hexachord.driver"], format: .xml, options: 0
+ )
+ try info.write(to: directory.file("root/Library/Extensions/HexachordAudio.kext/Contents/Info.plist"))
+ try directory.setPermissions(0o555, of: "root/Library/Extensions")
+ defer { try? directory.setPermissions(0o755, of: "root/Library/Extensions") }
+
+ let found = await LeftoverScanner(environment: environment(in: directory)).scan(app, installedApps: [app])
+ let scan = found.holdingBack(beyond: HelperReach(environment: environment(in: directory)), leaving: app.url)
+
+ let kext = try #require(scan.leftovers.first { $0.url.lastPathComponent == "HexachordAudio.kext" })
+ #expect(kext.requiresPrivileges)
+ #expect(kext.match.heldBack == .beyondTheHelper)
+ #expect(scan.leftovers.count == 1, "the kext was reached twice or its folder was offered")
+ }
+
/// Apple: "The system automatically uninstalls any system extensions when the user deletes the corresponding
/// app." The copy macOS activated in `/Library/SystemExtensions` is its own to remove, so it is never listed.
@Test func neverListsASystemExtensionMacOSRemovesWithItsApp() async throws {