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.

Work out the audio plug-in folders once per scan

Țugui Dragoș11c014b706b2
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
index 78d48232..21971e3f 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
@@ -409,10 +409,10 @@ public struct LeftoverScan: Sendable {
/// Holds back each audio plug-in other apps load on their own, unless something else already holds it back.
func holdingBack(plugInsOtherAppsLoadIn environment: SearchEnvironment) -> LeftoverScan {
- LeftoverScan(
+ let folders = Plugins.LoadedByOtherApps(environment: environment)
+ return LeftoverScan(
leftovers: leftovers.map {
- $0.match.heldBack == nil && Plugins.isLoadedByOtherApps($0.url, environment: environment)
- ? $0.heldBack(.loadedByOtherApps) : $0
+ $0.match.heldBack == nil && folders.holds($0.url) ? $0.heldBack(.loadedByOtherApps) : $0
},
unreadableLocations: unreadableLocations,
cutShortLocations: cutShortLocations,
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
index 453732f4..0147d534 100644
--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
@@ -160,6 +160,7 @@ public struct OrphanScanner: Sendable {
uniquingKeysWith: { first, _ in first }
)
let folders = manifestFolders
+ let loadedByOtherApps = Plugins.LoadedByOtherApps(environment: environment)
let given = Set(owners.filter { here.contains($0.value.lowercased()) }.keys.map { $0.lowercased() })
let kept = found.compactMap { entry -> (identifier: String, item: OrphanItem, holds: Bool?)? in
guard !exclusions.excludes(entry.item.url), !exclusions.excludes(bundleIdentifier: entry.identifier),
@@ -181,7 +182,7 @@ public struct OrphanScanner: Sendable {
item.heldBack = .signInPlugIn
return (entry.identifier, item)
}
- if item.heldBack == nil, Plugins.isLoadedByOtherApps(item.url, environment: environment) {
+ if item.heldBack == nil, loadedByOtherApps.holds(item.url) {
item.heldBack = .loadedByOtherApps
}
if item.leftAlone == nil, entry.holds == nil {
diff --git a/Packages/PeelCore/Sources/PeelCore/Plugins/Plugins.swift b/Packages/PeelCore/Sources/PeelCore/Plugins/Plugins.swift
index 59127fb3..b9cac0ab 100644
--- a/Packages/PeelCore/Sources/PeelCore/Plugins/Plugins.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Plugins/Plugins.swift
@@ -116,16 +116,24 @@ public enum Plugins {
Plugin.Category(folder).map { (folder.rawValue, $0) }
}
- /// Whether `url` is at or inside a folder of plug-ins music apps and other hosts load on their own, in the home's
- /// Library or the Mac's.
- static func isLoadedByOtherApps(_ url: URL, environment: SearchEnvironment) -> Bool {
- let path = PathPattern.comparablePath(of: url)
- return [environment.homeDirectory, environment.rootDirectory].contains { base in
- folders.contains { folder, category in
- let place = PathPattern.comparablePath(of: base.appending(path: "Library/\(folder)"))
- return category.isLoadedByOtherApps && PathComponents.isPath(path, inside: place)
+ /// The folders of plug-ins music apps and other hosts load on their own, in the home's Library and the Mac's,
+ /// worked out once for a scan that asks about each of its items.
+ struct LoadedByOtherApps: Sendable {
+ /// Each folder's names, split once.
+ private let places: [[String]]
+
+ init(environment: SearchEnvironment) {
+ let names = Plugins.folders.filter { $0.1.isLoadedByOtherApps }.map(\.0)
+ places = [environment.homeDirectory, environment.rootDirectory].flatMap { base in
+ names.map { PathComponents.of(PathPattern.comparablePath(of: base.appending(path: "Library/\($0)"))) }
}
}
+
+ /// Whether `url` is inside one of these folders, as `PathComponents.isPath(_:inside:)` tells.
+ func holds(_ url: URL) -> Bool {
+ let names = PathComponents.of(PathPattern.comparablePath(of: url))
+ return places.contains { names.count > $0.count && names.starts(with: $0) }
+ }
}
/// An installed app with what the matcher knows of it, made once per scan, since each plug-in is asked about every