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.

Say on Intel Software what Peel couldn't read

Țugui Dragoș943f5437fb69
diff --git a/GUIDE.md b/GUIDE.md
index 0e8886bc..c0099ebb 100644
--- a/GUIDE.md
+++ b/GUIDE.md
@@ -246,7 +246,7 @@ and how many items the others hold.
is shown and not selected.
- **Intel Software:** what still needs Rosetta, which macOS 27 is the last release to offer for most Intel software:
apps, the Intel-only parts inside other apps, plug-ins, drivers, background items, and the commands in
- `/usr/local`.
+ `/usr/local`. It names any folder or program it couldn't read, since something there may need Rosetta too.
- **Homebrew:** your formulae and casks, with Update, Clean Up (and two deeper ones: downloads older than 30 days, or
every download), Repair Taps, Check Health, Scan for Vulnerabilities, Upgrade, and Uninstall, or the command to run in
Terminal for a cask that asks for an administrator's password. Uninstall and the cleanups delete for good, as Homebrew
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index d5ba9219..1f274085 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -113206,6 +113206,112 @@
}
}
},
+ "Peel can’t read its list of app folders, so it didn’t look at the apps in the folders you added." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemůže přečíst svůj seznam složek aplikací, takže neprověřil aplikace ve složkách, které jste přidali."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kann seine Liste der App-Ordner nicht lesen und hat daher die Apps in den Ordnern, die du hinzugefügt hast, nicht geprüft."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no puede leer su lista de carpetas de apps, así que no ha revisado las apps de las carpetas que has añadido."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel ne peut pas lire sa liste de dossiers d’apps : il n’a donc pas examiné les apps des dossiers que vous avez ajoutés."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non riesce a leggere il suo elenco di cartelle delle app, quindi non ha esaminato le app nelle cartelle che hai aggiunto."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelはアプリのフォルダのリストを読み取れないため、追加したフォルダにあるアプリは調べていません。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel이 앱 폴더 목록을 읽을 수 없으므로 사용자가 추가한 폴더에 있는 앱을 살펴보지 않았습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan zijn lijst van mappen met apps niet lezen, dus heeft Peel de apps in de mappen die je hebt toegevoegd, niet bekeken."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie może odczytać swojej listy folderów z aplikacjami, więc nie sprawdził aplikacji w dodanych przez Ciebie folderach."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não consegue ler a lista de pastas de apps, então não examinou os apps das pastas que você adicionou."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu își poate citi lista de dosare de aplicații, așa că nu a examinat aplicațiile din dosarele adăugate de dvs."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не удается прочитать свой список папок приложений, поэтому он не проверил приложения в добавленных Вами папках."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan inte läsa sin lista över appmappar, så Peel tittade inte på apparna i de mappar som du har lagt till."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel, uygulama klasörleri listesini okuyamıyor, bu yüzden eklediğiniz klasörlerdeki uygulamalara bakmadı."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не може прочитати свій список папок програм, тож не переглядала програми в папках, які ви додали."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel无法读取其App文件夹列表,因此没有查看你添加的文件夹中的App。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel無法讀取它的App檔案夾列表,因此沒有查看你加入的檔案夾中的App。"
+ }
+ }
+ }
+ },
"Peel can’t read its record of who signs your apps" : {
"localizations" : {
"cs" : {
@@ -115136,6 +115242,112 @@
}
}
},
+ "Peel couldn’t read %@, so something there may need Rosetta." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemohl přečíst %@, takže tam může být něco, co potřebuje prostředí Rosetta."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel konnte %@ nicht lesen, daher könnte dort etwas Rosetta benötigen."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no ha podido leer %@, así que algo de ahí podría necesitar Rosetta."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel n’a pas pu lire %@, il peut donc s’y trouver quelque chose qui a besoin de Rosetta."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non è riuscito a leggere %@, quindi lì potrebbe esserci qualcosa che richiede Rosetta."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelは%@を読み取れなかったため、そこにRosettaが必要なものがある可能性があります。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel이 %@을(를) 읽을 수 없었으므로 그곳에 Rosetta가 필요한 항목이 있을 수 있습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kon %@ niet lezen, dus daar staat misschien iets dat Rosetta nodig heeft."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie mógł zajrzeć do %@, więc coś tam może wymagać Rosetty."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não conseguiu ler %@, então algo ali pode precisar do Rosetta."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu a putut citi %@, așa că ceva de acolo ar putea avea nevoie de Rosetta."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не удалось прочитать %@, поэтому там может быть что-то, чему нужна Rosetta."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kunde inte läsa %@, så något där kan behöva Rosetta."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel şu klasörleri okuyamadı: %@. Bu yüzden oradaki bir şey Rosetta gerektiriyor olabilir."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не вдалося прочитати %@, тож щось там може потребувати Rosetta."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel未能读取%@,因此其中可能有需要Rosetta的项目。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel無法讀取%@,因此那裡可能有需要Rosetta的項目。"
+ }
+ }
+ }
+ },
"Peel couldn’t read History" : {
"localizations" : {
"cs" : {
@@ -211924,6 +212136,346 @@
}
}
},
+ "^[%lld more item](inflect: true)" : {
+ "localizations" : {
+ "cs" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld další položky"
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld další položky"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld další položka"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld dalších položek"
+ }
+ }
+ }
+ }
+ },
+ "de" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld weiteres Objekt"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld weitere Objekte"
+ }
+ }
+ }
+ }
+ },
+ "es" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld de ítems más"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "un ítem más"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld ítems más"
+ }
+ }
+ }
+ }
+ },
+ "fr" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld d’autres éléments"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld autre élément"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld autres éléments"
+ }
+ }
+ }
+ }
+ },
+ "it" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "altri %lld di elementi"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "un altro elemento"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "altri %lld elementi"
+ }
+ }
+ }
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "その他%lld項目"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "그 외 항목 %lld개"
+ }
+ },
+ "nl" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "nog %lld onderdeel"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "nog %lld onderdelen"
+ }
+ }
+ }
+ }
+ },
+ "pl" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "jeszcze %lld rzeczy"
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "jeszcze %lld rzeczy"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "jeszcze %lld rzecz"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "jeszcze %lld rzeczy"
+ }
+ }
+ }
+ }
+ },
+ "pt" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "mais %lld de itens"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "mais %lld item"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "mais %lld itens"
+ }
+ }
+ }
+ }
+ },
+ "ro" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "încă %lld articole"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "încă %lld articol"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "încă %lld de articole"
+ }
+ }
+ }
+ }
+ },
+ "ru" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "еще %lld объекта"
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "еще %lld объектов"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "еще %lld объект"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "еще %lld объекта"
+ }
+ }
+ }
+ }
+ },
+ "sv" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld objekt till"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld objekt till"
+ }
+ }
+ }
+ }
+ },
+ "tr" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld öğe daha"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld öğe daha"
+ }
+ }
+ }
+ }
+ },
+ "uk" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "ще %lld елементи"
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "ще %lld елементів"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "ще %lld елемент"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "ще %lld елемента"
+ }
+ }
+ }
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "其他%lld个项目"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "其他%lld個項目"
+ }
+ }
+ }
+ },
"^[%lld more line](inflect: true)" : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift
index 24a68c3d..5914253b 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift
@@ -110,7 +110,7 @@ public enum AppInspector {
developer: signing.developer,
applicationGroups: signing.applicationGroups,
embeddedBundleIdentifiers: embeddedBundleIdentifiers(in: contents, isWrapped: layout.isWrapped),
- architectures: executable.map(MachOHeader.architectures(ofExecutableAt:)) ?? [],
+ architectures: executable.flatMap(MachOHeader.architectures(ofExecutableAt:)) ?? [],
isFromAppStore: isFromAppStore,
isSystemProtected: isSystemProtected,
enclosingPackage: url.enclosingPackage,
@@ -262,7 +262,9 @@ public enum AppInspector {
}
if !isWrapped {
- for bundle in IntelInspector.frameworkProcesses(inside: contents.deletingLastPathComponent()) {
+ var unread: [URL] = []
+ let app = contents.deletingLastPathComponent()
+ for bundle in IntelInspector.frameworkProcesses(inside: app, unreadable: &unread) {
let info = infoDictionary(in: bundle.appending(path: "Contents", directoryHint: .isDirectory))
if let identifier = info?["CFBundleIdentifier"] as? String { identifiers.append(identifier) }
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift b/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift
index 202b321c..ed96dab1 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift
@@ -28,6 +28,13 @@ public struct IntelFinding: Sendable, Hashable, Identifiable {
public struct IntelScan: Sendable {
public let findings: [IntelFinding]
+ /// What the scan couldn't read, each named once: folders it couldn't look into and programs it couldn't open, the
+ /// plug-in scan's included. Something there may need Rosetta.
+ public var unreadable: [URL] = []
+ /// True when macOS's privacy protection kept Peel out of one of them, which Full Disk Access lifts.
+ public var needsFullDiskAccess = false
+ /// The kinds of launchd jobs `launchctl` didn't describe in a form Peel can read, whose programs it never saw.
+ public var unansweredJobs: Set<BackgroundItem.Kind> = []
public func findings(of kind: IntelFinding.Kind) -> [IntelFinding] {
findings.filter { $0.kind == kind }
@@ -87,8 +94,8 @@ public enum IntelInspector {
@concurrent
public static func scan(
installedApps: [InstalledApp],
- plugins: [Plugin] = [],
- backgroundItems: [BackgroundItem] = [],
+ plugins: PluginScan = PluginScan(),
+ backgroundItems: BackgroundItems.Scan = BackgroundItems.Scan(),
exclusions: Exclusions = .none,
environment: SearchEnvironment = .current
) async -> IntelScan {
@@ -105,8 +112,8 @@ public enum IntelInspector {
@concurrent
static func scan(
installedApps: [InstalledApp],
- plugins: [Plugin],
- backgroundItems: [BackgroundItem],
+ plugins: PluginScan = PluginScan(),
+ backgroundItems: BackgroundItems.Scan = BackgroundItems.Scan(),
exclusions: Exclusions,
environment: SearchEnvironment = .current,
measure: FileSize.Measure
@@ -116,10 +123,16 @@ public enum IntelInspector {
var findings: [IntelFinding] = []
var seen: Set<String> = []
func isNew(_ url: URL) -> Bool { seen.insert(PathPattern.comparablePath(of: url)).inserted }
+ var unreadable: [URL] = []
for app in installedApps where !exclusions.excludes(app) {
guard !Task.isCancelled else { break }
- if app.isIntelOnly, isNew(app.url) {
+ // An app whose own program Peel couldn't read may be Intel only, so what it carries can't be told apart.
+ let refusedBefore = unreadable.count
+ let intelOnly = app.isIntelOnly
+ || app.architectures.isEmpty && isIntelOnly(bundle: app.url, unreadable: &unreadable)
+ guard unreadable.count == refusedBefore else { continue }
+ if intelOnly, isNew(app.url) {
findings.append(IntelFinding(
url: app.url,
kind: .app,
@@ -129,7 +142,7 @@ public enum IntelInspector {
))
continue
}
- for url in intelOnlyBundles(inside: app.url)
+ for url in intelOnlyBundles(inside: app.url, unreadable: &unreadable)
where !Task.isCancelled && !exclusions.excludes(url) && isNew(url) {
findings.append(IntelFinding(
url: url,
@@ -141,9 +154,9 @@ public enum IntelInspector {
}
}
- for plugin in plugins
- where !Task.isCancelled && !exclusions.excludes(plugin.url) && isIntelOnly(bundle: plugin.url)
- && isNew(plugin.url) {
+ unreadable += plugins.unreadable
+ for plugin in plugins.plugins where !Task.isCancelled && !exclusions.excludes(plugin.url) {
+ guard isIntelOnly(bundle: plugin.url, unreadable: &unreadable), isNew(plugin.url) else { continue }
findings.append(IntelFinding(
url: plugin.url,
kind: .plugin,
@@ -154,8 +167,9 @@ public enum IntelInspector {
))
}
- for url in bundles(in: driverDirectories(environment))
- where !Task.isCancelled && !exclusions.excludes(url) && isIntelOnly(bundle: url) && isNew(url) {
+ for url in bundles(in: driverDirectories(environment), unreadable: &unreadable)
+ where !Task.isCancelled && !exclusions.excludes(url) {
+ guard isIntelOnly(bundle: url, unreadable: &unreadable), isNew(url) else { continue }
findings.append(IntelFinding(
url: url,
kind: .driver,
@@ -166,8 +180,9 @@ public enum IntelInspector {
}
let printerDirectories = driverDirectories(environment, folders: [printers])
- for url in programs(in: printerDirectories)
- where !Task.isCancelled && !exclusions.excludes(url) && isIntelOnly(executable: url) && isNew(url) {
+ for url in programs(in: printerDirectories, unreadable: &unreadable)
+ where !Task.isCancelled && !exclusions.excludes(url) {
+ guard isIntelOnly(executable: url, unreadable: &unreadable), isNew(url) else { continue }
findings.append(IntelFinding(
url: url,
kind: .driver,
@@ -177,9 +192,9 @@ public enum IntelInspector {
))
}
- for item in backgroundItems where !Task.isCancelled {
+ for item in backgroundItems.items where !Task.isCancelled {
guard let program = item.program.map({ URL(filePath: $0) }), !exclusions.excludes(program) else { continue }
- guard isIntelOnly(executable: program), isNew(program) else { continue }
+ guard isIntelOnly(executable: program, unreadable: &unreadable), isNew(program) else { continue }
findings.append(IntelFinding(
url: program,
kind: .backgroundItem,
@@ -191,10 +206,11 @@ public enum IntelInspector {
// A command that leads into an app listed already is that app's.
let apps = findings.filter { $0.kind == .app }.map { PathPattern.comparablePath(of: $0.url) }
- for tool in tools(in: toolDirectories(environment)) where !Task.isCancelled && !exclusions.excludes(tool.url) {
+ for tool in tools(in: toolDirectories(environment), unreadable: &unreadable)
+ where !Task.isCancelled && !exclusions.excludes(tool.url) {
let path = PathPattern.comparablePath(of: tool.url)
guard !apps.contains(where: { PathComponents.isPath(path, inside: $0) }) else { continue }
- guard isIntelOnly(executable: tool.url), isNew(tool.url) else { continue }
+ guard isIntelOnly(executable: tool.url, unreadable: &unreadable), isNew(tool.url) else { continue }
findings.append(IntelFinding(
url: tool.url,
kind: .commandLineTool,
@@ -204,65 +220,84 @@ public enum IntelInspector {
))
}
+ var named: Set<String> = []
+ let unread = unreadable.filter {
+ !exclusions.excludes($0) && named.insert(PathPattern.comparablePath(of: $0)).inserted
+ }
return IntelScan(
findings: findings.sorted {
$0.size != $1.size ? SizeTotal([$0.size]) > SizeTotal([$1.size]) : $0.name < $1.name
- }
+ },
+ unreadable: unread,
+ needsFullDiskAccess: unread.contains { FullDiskAccess.canList($0) == .missing },
+ unansweredJobs: backgroundItems.unanswered
)
}
/// Helpers, plug-ins, and plain binaries inside an app that only have Intel code.
- static func intelOnlyBundles(inside bundle: URL) -> [URL] {
- let resources = resourceDirectories.flatMap { directory in
- processes(in: bundle.appending(path: directory, directoryHint: .isDirectory))
+ static func intelOnlyBundles(inside bundle: URL, unreadable: inout [URL]) -> [URL] {
+ var candidates = frameworkProcesses(inside: bundle, unreadable: &unreadable)
+ for directory in resourceDirectories {
+ let folder = bundle.appending(path: directory, directoryHint: .isDirectory)
+ candidates += processes(in: folder, unreadable: &unreadable)
}
- return (frameworkProcesses(inside: bundle) + resources).filter(isIntelOnlyProcess)
- + embeddedDirectories.flatMap { directory -> [URL] in
- let folder = bundle.appending(path: directory, directoryHint: .isDirectory)
- let names =
- (try? FileManager.default.contentsOfDirectory(atPath: folder.path(percentEncoded: false))) ?? []
- return names.map { folder.appending(path: $0) }.filter { url in
- var info = stat()
- guard lstat(url.path(percentEncoded: false), &info) == 0 else { return false }
- if info.st_mode & S_IFMT == S_IFDIR {
- return !url.pathExtension.isEmpty && isIntelOnly(bundle: url)
+ var found = candidates.filter { isIntelOnlyProcess($0, unreadable: &unreadable) }
+ for directory in embeddedDirectories {
+ let folder = bundle.appending(path: directory, directoryHint: .isDirectory)
+ for url in entries(of: folder, unreadable: &unreadable) {
+ var info = stat()
+ guard lstat(url.path(percentEncoded: false), &info) == 0 else { continue }
+ if info.st_mode & S_IFMT == S_IFDIR {
+ if !url.pathExtension.isEmpty, isIntelOnly(bundle: url, unreadable: &unreadable) {
+ found.append(url)
}
+ } else if isRunnable(info), isIntelOnly(executable: url, unreadable: &unreadable),
+ MachOHeader.isProgram(at: url) == true {
// A library or a bundle kept beside the programs runs in the process that loads it.
- return info.st_mode & S_IFMT == S_IFREG && isIntelOnly(executable: url)
- && MachOHeader.isProgram(at: url)
+ found.append(url)
}
}
+ }
+ return found
}
/// Returns the processes under `Contents/Frameworks`: apps and XPC services kept there directly, as every
/// Electron app keeps its helpers, and those in each framework's `XPCServices` and `Helpers` folders, at the top
/// of each version, as Sparkle keeps its updater, and in its `Resources`, as Squirrel does. `Versions/Current` is
/// skipped: it is a link to one of the versions beside it, so following it would report the same bundle twice.
- static func frameworkProcesses(inside bundle: URL) -> [URL] {
+ static func frameworkProcesses(inside bundle: URL, unreadable: inout [URL]) -> [URL] {
let frameworks = bundle.appending(path: "Contents/Frameworks", directoryHint: .isDirectory)
- return entries(of: frameworks).flatMap { url -> [URL] in
- if processExtensions.contains(url.pathExtension.lowercased()) { return [url] }
- guard url.pathExtension.lowercased() == "framework" else { return [] }
- let versions = entries(of: url.appending(path: "Versions", directoryHint: .isDirectory))
+ var found: [URL] = []
+ for url in entries(of: frameworks, unreadable: &unreadable) {
+ if processExtensions.contains(url.pathExtension.lowercased()) {
+ found.append(url)
+ continue
+ }
+ guard url.pathExtension.lowercased() == "framework" else { continue }
+ let versions = entries(of: url.appending(path: "Versions", directoryHint: .isDirectory), unreadable: &unreadable)
.filter { $0.lastPathComponent != "Current" }
- return (versions + [url]).flatMap { version in
- let bundles = ["XPCServices", "Helpers"].flatMap { name in
+ for version in versions + [url] {
+ for name in ["XPCServices", "Helpers"] {
// At the top of a versioned framework these are links into `Versions/Current`, already read.
let folder = version.appending(path: name, directoryHint: .isDirectory)
- guard version != url || folder.isRealFolder else { return [URL]() }
- return entries(of: folder).filter { processExtensions.contains($0.pathExtension.lowercased()) }
+ guard version != url || folder.isRealFolder else { continue }
+ found += entries(of: folder, unreadable: &unreadable)
+ .filter { processExtensions.contains($0.pathExtension.lowercased()) }
}
+ found += processes(in: version, unreadable: &unreadable)
let resources = version.appending(path: "Resources", directoryHint: .isDirectory)
- let kept = version != url || resources.isRealFolder ? processes(in: resources) : []
- return bundles + processes(in: version) + kept
+ if version != url || resources.isRealFolder {
+ found += processes(in: resources, unreadable: &unreadable)
+ }
}
}
+ return found
}
/// What in `folder` can run as a process of its own: a bundle that runs as one, or a file that can be run. Links
/// are passed over, since at the top of a framework they lead into a version read on its own.
- private static func processes(in folder: URL) -> [URL] {
- entries(of: folder).filter { url in
+ private static func processes(in folder: URL, unreadable: inout [URL]) -> [URL] {
+ entries(of: folder, unreadable: &unreadable).filter { url in
var info = stat()
guard lstat(url.path(percentEncoded: false), &info) == 0 else { return false }
switch info.st_mode & S_IFMT {
@@ -275,66 +310,122 @@ public enum IntelInspector {
/// Whether `url`, a bundle that runs as a process or a file that can be run, has only Intel code, and a file is a
/// program rather than a library another program loads.
- private static func isIntelOnlyProcess(_ url: URL) -> Bool {
+ private static func isIntelOnlyProcess(_ url: URL, unreadable: inout [URL]) -> Bool {
url.hasDirectoryPath || url.isRealFolder
- ? isIntelOnly(bundle: url) : isIntelOnly(executable: url) && MachOHeader.isProgram(at: url)
+ ? isIntelOnly(bundle: url, unreadable: &unreadable)
+ : isIntelOnly(executable: url, unreadable: &unreadable) && MachOHeader.isProgram(at: url) == true
}
- private static func entries(of directory: URL) -> [URL] {
- let names = (try? FileManager.default.contentsOfDirectory(atPath: directory.path(percentEncoded: false))) ?? []
+ /// The entries of `directory`. One Peel can't list adds the folder that kept it out to `unreadable`.
+ private static func entries(of directory: URL, unreadable: inout [URL]) -> [URL] {
+ guard let names = try? FileManager.default.contentsOfDirectory(atPath: directory.path(percentEncoded: false))
+ else {
+ if let folder = refusedFolder(directory) { unreadable.append(folder) }
+ return []
+ }
return names.map { directory.appending(path: $0) }
}
- static func isIntelOnly(bundle url: URL) -> Bool {
- guard let executable = executable(of: url) else { return false }
- return isIntelOnly(executable: executable)
+ /// The folder that kept Peel out of `folder`: `folder` itself when Peel can see it but not list it, or the folder
+ /// around it Peel can't look into. Nil when nothing is there, or a file is, which hides nothing.
+ static func refusedFolder(_ folder: URL) -> URL? {
+ var info = stat()
+ if stat(folder.path(percentEncoded: false), &info) == 0 {
+ return info.st_mode & S_IFMT == S_IFDIR ? folder : nil
+ }
+ guard ![ENOENT, ENOTDIR, ELOOP].contains(errno) else { return nil }
+ let around = folder.deletingLastPathComponent()
+ return around.path(percentEncoded: false) == folder.path(percentEncoded: false) ? nil : refusedFolder(around)
+ }
+
+ /// Notes `program`, which macOS wouldn't let Peel read, or the folder around it Peel can't look into.
+ private static func noteRefused(_ program: URL, in unreadable: inout [URL]) {
+ unreadable.append(program.isThere ? program : refusedFolder(program.deletingLastPathComponent()) ?? program)
}
- static func isIntelOnly(executable url: URL) -> Bool {
- MachOHeader.architectures(ofExecutableAt: url) == [.x86_64]
+ /// Whether a file can be run by anyone: one that only root may run still runs, though Peel can't read it.
+ private static func isRunnable(_ info: stat) -> Bool {
+ info.st_mode & S_IFMT == S_IFREG && info.st_mode & 0o111 != 0
+ }
+
+ static func isIntelOnly(bundle url: URL, unreadable: inout [URL]) -> Bool {
+ guard let executable = executable(of: url, unreadable: &unreadable) else { return false }
+ return isIntelOnly(executable: executable, unreadable: &unreadable)
+ }
+
+ static func isIntelOnly(executable url: URL, unreadable: inout [URL]) -> Bool {
+ guard let architectures = MachOHeader.architectures(ofExecutableAt: url) else {
+ noteRefused(url, in: &unreadable)
+ return false
+ }
+ return architectures == [.x86_64]
}
/// The binary a bundle runs, from its Info.plist or, failing that, the name of the bundle.
- static func executable(of bundle: URL) -> URL? {
+ static func executable(of bundle: URL, unreadable: inout [URL]) -> URL? {
let contents = bundle.appending(path: "Contents", directoryHint: .isDirectory)
let info = BoundedRead.propertyList(at: contents.appending(path: "Info.plist"))
let name = (info?["CFBundleExecutable"] as? String) ?? bundle.deletingPathExtension().lastPathComponent
// The second place is for a flat bundle, which keeps its binary at its top level.
- let candidates = [contents.appending(path: "MacOS/\(name)"), bundle.appending(path: name)]
- return candidates.first { FileManager.default.isExecutableFile(atPath: $0.path(percentEncoded: false)) }
+ for candidate in [contents.appending(path: "MacOS/\(name)"), bundle.appending(path: name)] {
+ var status = stat()
+ if stat(candidate.path(percentEncoded: false), &status) == 0 {
+ if isRunnable(status) { return candidate }
+ } else if ![ENOENT, ENOTDIR, ELOOP].contains(errno) {
+ if let folder = refusedFolder(candidate.deletingLastPathComponent()) { unreadable.append(folder) }
+ return nil
+ }
+ }
+ return nil
}
/// `ds` is a TWAIN data source, which Apple's Technical Note TN2088 puts in `Image Capture/TWAIN Data Sources`.
static let driverExtensions: Set<String> = ["app", "plugin", "bundle", "driver", "qlgenerator", "mdimporter", "ds"]
- static func bundles(in directories: [String]) -> [URL] {
- directories.flatMap { directory -> [URL] in
+ static func bundles(in directories: [String], unreadable: inout [URL]) -> [URL] {
+ var bundles: [URL] = []
+ for directory in directories {
let url = URL(filePath: directory, directoryHint: .isDirectory)
+ var refused: [URL] = []
guard let enumerator = FileManager.default.enumerator(
at: url,
includingPropertiesForKeys: [.isDirectoryKey],
- options: [.skipsHiddenFiles, .skipsPackageDescendants]
- ) else { return [] }
- var bundles: [URL] = []
+ options: [.skipsHiddenFiles, .skipsPackageDescendants],
+ errorHandler: { folder, _ in
+ refused.append(folder)
+ return true
+ }
+ ) else {
+ if let folder = refusedFolder(url) { unreadable.append(folder) }
+ continue
+ }
for case let item as URL in enumerator {
guard !Task.isCancelled else { break }
if driverExtensions.contains(item.pathExtension) { bundles.append(item) }
}
- return bundles
+ unreadable += refused.compactMap(refusedFolder)
}
+ return bundles
}
/// The programs in `directories` that sit outside every bundle: one inside a bundle is the bundle's.
- static func programs(in directories: [String]) -> [URL] {
- let keys: Set<URLResourceKey> = [.isRegularFileKey, .isExecutableKey]
- return directories.flatMap { directory -> [URL] in
+ static func programs(in directories: [String], unreadable: inout [URL]) -> [URL] {
+ var programs: [URL] = []
+ for directory in directories {
let url = URL(filePath: directory, directoryHint: .isDirectory)
+ var refused: [URL] = []
guard let enumerator = FileManager.default.enumerator(
at: url,
- includingPropertiesForKeys: Array(keys),
- options: [.skipsHiddenFiles, .skipsPackageDescendants]
- ) else { return [] }
- var programs: [URL] = []
+ includingPropertiesForKeys: [.isDirectoryKey],
+ options: [.skipsHiddenFiles, .skipsPackageDescendants],
+ errorHandler: { folder, _ in
+ refused.append(folder)
+ return true
+ }
+ ) else {
+ if let folder = refusedFolder(url) { unreadable.append(folder) }
+ continue
+ }
for case let item as URL in enumerator {
guard !Task.isCancelled else { break }
if driverExtensions.contains(item.pathExtension) {
@@ -344,31 +435,37 @@ public enum IntelInspector {
}
continue
}
- let values = try? item.resourceValues(forKeys: keys)
- if values?.isRegularFile == true, values?.isExecutable == true, MachOHeader.isProgram(at: item) {
- programs.append(item)
+ var info = stat()
+ guard lstat(item.path(percentEncoded: false), &info) == 0, isRunnable(info) else { continue }
+ switch MachOHeader.isProgram(at: item) {
+ case true?: programs.append(item)
+ case nil: noteRefused(item, in: &unreadable)
+ case false?: break
}
}
- return programs
+ unreadable += refused.compactMap(refusedFolder)
}
+ return programs
}
/// The programs the commands in `directories` run, each under the command's name. A command is often a link,
/// as every one a Homebrew in `/usr/local` makes into its `Cellar`, and the program it leads to is what runs.
- static func tools(in directories: [String]) -> [(name: String, url: URL)] {
- directories.flatMap { directory -> [(name: String, url: URL)] in
+ static func tools(in directories: [String], unreadable: inout [URL]) -> [(name: String, url: URL)] {
+ var tools: [(name: String, url: URL)] = []
+ for directory in directories {
let folder = URL(filePath: directory, directoryHint: .isDirectory)
- let names = (try? FileManager.default.contentsOfDirectory(atPath: directory)) ?? []
- return names.compactMap { name in
- let program = folder.appending(path: name).resolvingSymlinksInPath()
+ for command in entries(of: folder, unreadable: &unreadable) {
+ let program = command.resolvingSymlinksInPath()
var info = stat()
- let path = program.path(percentEncoded: false)
- guard stat(path, &info) == 0, info.st_mode & S_IFMT == S_IFREG,
- FileManager.default.isExecutableFile(atPath: path)
- else { return nil }
- return (name, program)
+ if stat(program.path(percentEncoded: false), &info) == 0 {
+ if isRunnable(info) { tools.append((command.lastPathComponent, program)) }
+ } else if ![ENOENT, ENOTDIR, ELOOP].contains(errno),
+ let place = refusedFolder(program.deletingLastPathComponent()) {
+ unreadable.append(place)
+ }
}
}
+ return tools
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/MachOHeader.swift b/Packages/PeelCore/Sources/PeelCore/Apps/MachOHeader.swift
index 1403a9a5..fa282ada 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/MachOHeader.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/MachOHeader.swift
@@ -13,55 +13,62 @@ enum MachOHeader {
/// `MH_EXECUTE` in `<mach-o/loader.h>`: a program, as opposed to a library or a bundle another program loads.
private static let programFileType: UInt32 = 0x2
- /// Returns the architectures of the executable at `url`. Whatever is at that path gets opened, and a named
- /// pipe opened for reading would wait forever for a writer. `O_NONBLOCK` returns at once, and only a regular
- /// file is read.
- static func architectures(ofExecutableAt url: URL) -> Set<Architecture> {
+ /// Returns the architectures of the executable at `url`, or nil when something is there that Peel can't read.
+ /// Whatever is at that path gets opened, and a named pipe opened for reading would wait forever for a writer.
+ /// `O_NONBLOCK` returns at once, and only a regular file is read.
+ static func architectures(ofExecutableAt url: URL) -> Set<Architecture>? {
let descriptor = open(url.path(percentEncoded: false), O_RDONLY | O_NONBLOCK | O_CLOEXEC)
- guard descriptor >= 0 else { return [] }
+ guard descriptor >= 0 else { return nothingIsThere(errno) ? [] : nil }
defer { close(descriptor) }
var info = stat()
guard fstat(descriptor, &info) == 0, info.st_mode & S_IFMT == S_IFREG else { return [] }
var bytes = [UInt8](repeating: 0, count: 4_096)
let count = read(descriptor, &bytes, bytes.count)
+ guard count >= 0 else { return nil }
return count > 0 ? architectures(inHeader: Array(bytes[0..<count])) : []
}
- /// Whether the file at `url` is a program of its own rather than code another program loads. A universal
- /// file is judged by its first slice, since every slice of one file is built as the same kind.
- static func isProgram(at url: URL) -> Bool {
+ /// Whether the file at `url` is a program of its own rather than code another program loads, or nil when it is
+ /// there and Peel can't read it. A universal file is judged by its first slice, since every slice of one file is
+ /// built as the same kind.
+ static func isProgram(at url: URL) -> Bool? {
let descriptor = open(url.path(percentEncoded: false), O_RDONLY | O_NONBLOCK | O_CLOEXEC)
- guard descriptor >= 0 else { return false }
+ guard descriptor >= 0 else { return nothingIsThere(errno) ? false : nil }
defer { close(descriptor) }
var info = stat()
guard fstat(descriptor, &info) == 0, info.st_mode & S_IFMT == S_IFREG else { return false }
- func bytes(at offset: off_t, count: Int) -> [UInt8] {
+ func bytes(at offset: off_t, count: Int) -> [UInt8]? {
var buffer = [UInt8](repeating: 0, count: count)
let read = pread(descriptor, &buffer, count, offset)
- return read > 0 ? Array(buffer[0..<read]) : []
+ return read >= 0 ? Array(buffer[0..<read]) : nil
}
func isAProgram(_ header: [UInt8]) -> Bool {
let magic = bigEndianUInt32(header, at: 0)
return (magic == machMagic64Swapped || magic == machMagicSwapped)
&& littleEndianUInt32(header, at: 12) == programFileType
}
- let header = bytes(at: 0, count: 32)
+ guard let header = bytes(at: 0, count: 32) else { return nil }
switch bigEndianUInt32(header, at: 0) {
case machMagic64Swapped:
return isAProgram(header)
case fatMagic:
guard let offset = bigEndianUInt32(header, at: 16) else { return false }
- return isAProgram(bytes(at: off_t(offset), count: 16))
+ return bytes(at: off_t(offset), count: 16).map(isAProgram)
case fatMagic64:
guard let high = bigEndianUInt32(header, at: 16), let low = bigEndianUInt32(header, at: 20) else {
return false
}
- return isAProgram(bytes(at: off_t(UInt64(high) << 32 | UInt64(low)), count: 16))
+ return bytes(at: off_t(UInt64(high) << 32 | UInt64(low)), count: 16).map(isAProgram)
default:
return false
}
}
+ /// Whether `open` failed because nothing is there to read, a link that leads nowhere included.
+ private static func nothingIsThere(_ error: Int32) -> Bool {
+ [ENOENT, ENOTDIR, ELOOP].contains(error)
+ }
+
static func architectures(inHeader bytes: [UInt8]) -> Set<Architecture> {
guard let magic = bigEndianUInt32(bytes, at: 0) else { return [] }
diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift
index 61a7ec2c..46afa547 100644
--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift
+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift
@@ -10,6 +10,11 @@ public enum BackgroundItems {
public let items: [BackgroundItem]
/// The kinds that may be missing jobs, because `launchctl` answered about them in a form Peel cannot read.
public let unanswered: Set<BackgroundItem.Kind>
+
+ public init(items: [BackgroundItem] = [], unanswered: Set<BackgroundItem.Kind> = []) {
+ self.items = items
+ self.unanswered = unanswered
+ }
}
/// A loaded job no file in the three folders declares, as `launchctl` described it.
diff --git a/Packages/PeelCore/Sources/PeelCore/Plugins/Plugins.swift b/Packages/PeelCore/Sources/PeelCore/Plugins/Plugins.swift
index 8937a46a..151fd39e 100644
--- a/Packages/PeelCore/Sources/PeelCore/Plugins/Plugins.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Plugins/Plugins.swift
@@ -85,6 +85,12 @@ public struct PluginScan: Sendable {
public var unreadable: [URL] = []
/// True when macOS's privacy protection kept Peel out of one of them, which Full Disk Access lifts.
public var needsFullDiskAccess = false
+
+ public init(plugins: [Plugin] = [], unreadable: [URL] = [], needsFullDiskAccess: Bool = false) {
+ self.plugins = plugins
+ self.unreadable = unreadable
+ self.needsFullDiskAccess = needsFullDiskAccess
+ }
}
/// Finds the plug-ins that apps have installed in the folders macOS loads plug-ins from. Apple's own
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
index 6602e53a..90146a20 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
@@ -102,7 +102,7 @@ struct AppInspectorTests {
/// Reads `/usr/bin/true`, the real binary the `universal` fixture above is modeled on.
@Test func readsARealBinaryTheSameWay() {
- #expect(MachOHeader.architectures(ofExecutableAt: URL(filePath: "/usr/bin/true")).contains(.arm64))
+ #expect(MachOHeader.architectures(ofExecutableAt: URL(filePath: "/usr/bin/true"))?.contains(.arm64) == true)
}
@Test func inspectsBundleOnDisk() throws {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift
index 1ee7dcb1..374c853f 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift
@@ -50,8 +50,8 @@ struct IntelInspectorTests {
)
let printers = directory.url.appending(path: "Printers").path(percentEncoded: false)
- #expect(MachOHeader.isProgram(at: filter))
- #expect(IntelInspector.programs(in: [printers]).map(\.lastPathComponent) == ["filter"])
+ #expect(MachOHeader.isProgram(at: filter) == true)
+ #expect(readable { IntelInspector.programs(in: [printers], unreadable: &$0) }.map(\.lastPathComponent) == ["filter"])
}
/// The drivers, the background items, and the tools are scanned after the apps, and those later steps must
@@ -77,8 +77,6 @@ struct IntelInspectorTests {
let stop = try await unanswered.stop {
_ = await IntelInspector.scan(
installedApps: installed,
- plugins: [],
- backgroundItems: [],
exclusions: .none,
environment: environment,
measure: unanswered.measure
@@ -104,11 +102,12 @@ struct IntelInspectorTests {
let walked = await Task {
withUnsafeCurrentTask { $0?.cancel() }
- return (IntelInspector.bundles(in: [printers]), IntelInspector.programs(in: [printers]))
+ let bundles = readable { IntelInspector.bundles(in: [printers], unreadable: &$0) }
+ return (bundles, readable { IntelInspector.programs(in: [printers], unreadable: &$0) })
}.value
- #expect(IntelInspector.bundles(in: [printers]).count == 3)
- #expect(IntelInspector.programs(in: [printers]).count == 3)
+ #expect(readable { IntelInspector.bundles(in: [printers], unreadable: &$0) }.count == 3)
+ #expect(readable { IntelInspector.programs(in: [printers], unreadable: &$0) }.count == 3)
#expect(walked.0.isEmpty)
#expect(walked.1.isEmpty)
}
@@ -124,7 +123,8 @@ struct IntelInspectorTests {
}
let printers = directory.url.appending(path: "Printers").path(percentEncoded: false)
- let folders = IntelInspector.programs(in: [printers]).map { $0.deletingLastPathComponent().lastPathComponent }
+ let folders = readable { IntelInspector.programs(in: [printers], unreadable: &$0) }
+ .map { $0.deletingLastPathComponent().lastPathComponent }
#expect(folders.sorted() == ["Filters", "Helpers", "Scripts", "Tools", "Utilities"])
}
@@ -141,6 +141,13 @@ struct IntelInspectorTests {
return directory.url.appending(path: path, directoryHint: .isDirectory)
}
+ /// Runs one of the scan's walks over fixtures that can all be read, so it names nothing it couldn't read.
+ private func readable<T>(_ walk: (inout [URL]) -> T) -> T {
+ var unread: [URL] = []
+ defer { #expect(unread.isEmpty, "named \(unread)") }
+ return walk(&unread)
+ }
+
private func environment(in directory: borrowing TemporaryDirectory) -> SearchEnvironment {
SearchEnvironment(
homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),
@@ -154,9 +161,9 @@ struct IntelInspectorTests {
let universalApp = try bundle(directory, "Universal.app", cpuTypes: [intel, appleSilicon])
let appleApp = try bundle(directory, "Apple.app", cpuTypes: [appleSilicon])
- #expect(IntelInspector.isIntelOnly(bundle: intelApp))
- #expect(!IntelInspector.isIntelOnly(bundle: universalApp))
- #expect(!IntelInspector.isIntelOnly(bundle: appleApp))
+ #expect(readable { IntelInspector.isIntelOnly(bundle: intelApp, unreadable: &$0) })
+ #expect(!readable { IntelInspector.isIntelOnly(bundle: universalApp, unreadable: &$0) })
+ #expect(!readable { IntelInspector.isIntelOnly(bundle: appleApp, unreadable: &$0) })
}
/// Apple's macOS 27 note names the folders its own Intel list may miss: "~/Library/Audio/Plug-Ins/*,
@@ -172,8 +179,6 @@ struct IntelInspectorTests {
let scan = await IntelInspector.scan(
installedApps: [],
- plugins: [],
- backgroundItems: [],
exclusions: .none,
environment: SearchEnvironment(homeDirectory: home, rootDirectory: root),
measure: { _ in 1 }
@@ -189,8 +194,6 @@ struct IntelInspectorTests {
let scan = await IntelInspector.scan(
installedApps: [],
- plugins: [],
- backgroundItems: [],
exclusions: .none,
environment: SearchEnvironment(
homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),
@@ -220,8 +223,6 @@ struct IntelInspectorTests {
let scan = await IntelInspector.scan(
installedApps: [],
- plugins: [],
- backgroundItems: [],
exclusions: .none,
environment: SearchEnvironment(
homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),
@@ -249,9 +250,11 @@ struct IntelInspectorTests {
ofItemAtPath: plainHelper.path(percentEncoded: false)
)
- let found = IntelInspector.intelOnlyBundles(
- inside: directory.url.appending(path: "Universal.app", directoryHint: .isDirectory)
- )
+ let found = readable {
+ IntelInspector.intelOnlyBundles(
+ inside: directory.url.appending(path: "Universal.app", directoryHint: .isDirectory), unreadable: &$0
+ )
+ }
#expect(Set(found.map(\.lastPathComponent)) == ["Launcher.app", "Old.appex", "updater"])
}
@@ -271,7 +274,7 @@ struct IntelInspectorTests {
_ = try bundle(directory, "\(appLibrary)/SystemExtensions/Filter.systemextension", cpuTypes: [intel])
let app = directory.url.appending(path: "Universal.app", directoryHint: .isDirectory)
- let found = IntelInspector.intelOnlyBundles(inside: app)
+ let found = readable { IntelInspector.intelOnlyBundles(inside: app, unreadable: &$0) }
#expect(Set(found.map(\.lastPathComponent)) == [
"ffmpeg", "Preview.qlgenerator", "Importer.mdimporter", "Filter.systemextension",
@@ -305,7 +308,7 @@ struct IntelInspectorTests {
_ = try bundle(directory, "Universal.app/Contents/SharedSupport/Installer.app", cpuTypes: [intel])
let app = directory.url.appending(path: "Universal.app", directoryHint: .isDirectory)
- let found = IntelInspector.intelOnlyBundles(inside: app)
+ let found = readable { IntelInspector.intelOnlyBundles(inside: app, unreadable: &$0) }
#expect(found.map(\.lastPathComponent).sorted() == ["Autoupdate", "Installer.app", "ShipIt", "Updater.app", "helper"])
}
@@ -322,7 +325,7 @@ struct IntelInspectorTests {
withDestinationPath: "../Cellar/tool/1.0/bin/tool"
)
- let tools = IntelInspector.tools(in: [bin.path(percentEncoded: false)])
+ let tools = readable { IntelInspector.tools(in: [bin.path(percentEncoded: false)], unreadable: &$0) }
#expect(tools.map(\.name) == ["tool"])
#expect(tools.map { PathPattern.comparablePath(of: $0.url) } == [PathPattern.comparablePath(of: program)])
@@ -335,8 +338,6 @@ struct IntelInspectorTests {
let scan = await IntelInspector.scan(
installedApps: [],
- plugins: [],
- backgroundItems: [],
exclusions: .none,
environment: SearchEnvironment(
homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),
@@ -364,9 +365,11 @@ struct IntelInspectorTests {
ofItemAtPath: library.path(percentEncoded: false)
)
- let found = IntelInspector.intelOnlyBundles(
- inside: directory.url.appending(path: "Electron.app", directoryHint: .isDirectory)
- )
+ let found = readable {
+ IntelInspector.intelOnlyBundles(
+ inside: directory.url.appending(path: "Electron.app", directoryHint: .isDirectory), unreadable: &$0
+ )
+ }
#expect(Set(found.map(\.lastPathComponent)) == ["Electron Helper (GPU).app", "Installer.xpc", "com.example.helper.app"])
}
@@ -388,9 +391,11 @@ struct IntelInspectorTests {
withDestinationPath: "Versions/Current/XPCServices"
)
- let found = IntelInspector.intelOnlyBundles(
- inside: directory.url.appending(path: "Updater.app", directoryHint: .isDirectory)
- )
+ let found = readable {
+ IntelInspector.intelOnlyBundles(
+ inside: directory.url.appending(path: "Updater.app", directoryHint: .isDirectory), unreadable: &$0
+ )
+ }
#expect(found.filter { $0.lastPathComponent == "Installer.xpc" }.count == 1, "listed under \(found.map { $0.path(percentEncoded: false) })")
}
@@ -414,8 +419,7 @@ struct IntelInspectorTests {
let scan = await IntelInspector.scan(
installedApps: [],
- plugins: [],
- backgroundItems: [job("com.example.one"), job("com.example.two")],
+ backgroundItems: BackgroundItems.Scan(items: [job("com.example.one"), job("com.example.two")]),
exclusions: .none,
environment: environment(in: directory),
measure: { _ in 1 }
@@ -433,15 +437,15 @@ struct IntelInspectorTests {
let pipe = folder.appending(path: "Pipe")
try #require(mkfifo(pipe.path(percentEncoded: false), 0o755) == 0)
- #expect(MachOHeader.architectures(ofExecutableAt: pipe).isEmpty)
+ #expect(MachOHeader.architectures(ofExecutableAt: pipe) == [])
}
@Test func readsTheExecutableNamedInTheBundle() throws {
let directory = try TemporaryDirectory()
let app = try bundle(directory, "Intel.app", cpuTypes: [intel])
- let executable = try #require(IntelInspector.executable(of: app))
+ let executable = try #require(readable { IntelInspector.executable(of: app, unreadable: &$0) })
#expect(executable.lastPathComponent == "Intel")
- #expect(IntelInspector.executable(of: directory.url.appending(path: "Missing.app")) == nil)
+ #expect(readable { IntelInspector.executable(of: directory.url.appending(path: "Missing.app"), unreadable: &$0) } == nil)
}
@Test func reportsIntelAppsWithTheirSize() async throws {
@@ -463,8 +467,6 @@ struct IntelInspectorTests {
// An app that did not answer in time is still Intel only: it is listed, with a size nobody knows.
let slow = await IntelInspector.scan(
installedApps: [app],
- plugins: [],
- backgroundItems: [],
exclusions: .none,
environment: environment(in: directory)
) { _ in nil }
@@ -494,9 +496,54 @@ struct IntelInspectorTests {
)
}
- let found = IntelInspector.intelOnlyBundles(inside: app)
+ let found = readable { IntelInspector.intelOnlyBundles(inside: app, unreadable: &$0) }
#expect(found.isEmpty, "a library inside an app was reported: \(found.map(\.lastPathComponent))")
#expect(!IntelInspector.embeddedDirectories.contains("Contents/Frameworks"))
}
+
+ @Test(.permissionsHold) func namesWhatItCouldNotRead() async throws {
+ let directory = try TemporaryDirectory()
+ let closedDrivers = try directory.directory("root/Library/Printers/Closed")
+ let hiddenFilter = try directory.file("root/Library/Printers/Closed/filter", contents: intelHeader(fileType: 2))
+ try directory.setPermissions(0o755, of: hiddenFilter)
+ let groupsFilter = try directory.file("root/Library/Printers/Vendor/filter", contents: intelHeader(fileType: 2))
+ let tool = try directory.file("root/usr/local/bin/tool", contents: fatHeader([intel]))
+ let agent = try directory.file("Agents/agent", contents: fatHeader([intel]))
+ let universal = try bundle(directory, "Universal.app", cpuTypes: [intel, appleSilicon])
+ _ = try bundle(directory, "Universal.app/Contents/Library/LoginItems/Launcher.app", cpuTypes: [intel])
+ let closedLibrary = universal.appending(path: "Contents/Library", directoryHint: .isDirectory)
+ let closedApp = try bundle(directory, "Closed.app", cpuTypes: [intel])
+ let closedProgram = closedApp.appending(path: "Contents/MacOS/Closed")
+ try directory.setPermissions(0o010, of: groupsFilter)
+ for program in [tool, agent, closedProgram] { try directory.setPermissions(0o311, of: program) }
+ for folder in [closedDrivers, closedLibrary] { try directory.setPermissions(0o000, of: folder) }
+ defer { for folder in [closedDrivers, closedLibrary] { try? directory.setPermissions(0o755, of: folder) } }
+ let plugInFolder = directory.url.appending(path: "home/Library/Audio/Plug-Ins/VST3/Vendor", directoryHint: .isDirectory)
+ let job = BackgroundItem(
+ label: "org.example.agent", kind: .agent, source: .userLibrary, plistURL: nil,
+ program: agent.path(percentEncoded: false), runsAtLoad: false, keepsAlive: false,
+ ownerBundleIdentifier: nil, ownerName: nil, ownerURL: nil, isOrphan: false, state: .loaded,
+ isDisabled: false
+ )
+
+ let scan = await IntelInspector.scan(
+ installedApps: [
+ InstalledApp(url: universal, bundleIdentifier: "org.example.universal", name: "Universal", architectures: [.x86_64, .arm64]),
+ InstalledApp(url: closedApp, bundleIdentifier: "org.example.closed", name: "Closed", architectures: []),
+ ],
+ plugins: PluginScan(unreadable: [plugInFolder]),
+ backgroundItems: BackgroundItems.Scan(items: [job], unanswered: [.daemon]),
+ exclusions: .none,
+ environment: environment(in: directory),
+ measure: { _ in 1 }
+ )
+
+ #expect(scan.findings.isEmpty, "found \(scan.findings.map(\.name))")
+ let expected = [closedDrivers, groupsFilter, tool, agent, closedLibrary, closedProgram, plugInFolder]
+ let named = scan.unreadable.map(PathPattern.comparablePath(of:)).sorted()
+ #expect(named == expected.map(PathPattern.comparablePath(of:)).sorted())
+ #expect(!scan.needsFullDiskAccess)
+ #expect(scan.unansweredJobs == [.daemon])
+ }
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/IntelPluginHostTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/IntelPluginHostTests.swift
index 8ef6207f..889b9ecd 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/IntelPluginHostTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/IntelPluginHostTests.swift
@@ -17,7 +17,7 @@ struct IntelPluginHostTests {
#expect(Set(Plugin.Category.intelHostPrograms.keys) == Set(ownProcess))
for (category, program) in Plugin.Category.intelHostPrograms {
let architectures = MachOHeader.architectures(ofExecutableAt: URL(filePath: program))
- #expect(architectures.contains(.x86_64), "\(category): \(program)")
+ #expect(architectures?.contains(.x86_64) == true, "\(category): \(program)")
}
}
}
diff --git a/Peel/Model/BackgroundItemLibrary.swift b/Peel/Model/BackgroundItemLibrary.swift
index f1bac5ba..7e4fd8e3 100644
--- a/Peel/Model/BackgroundItemLibrary.swift
+++ b/Peel/Model/BackgroundItemLibrary.swift
@@ -99,8 +99,13 @@ final class BackgroundItemLibrary {
extension BackgroundItemLibrary {
/// What the page says when some jobs may be missing, or nil when macOS answered about every kind.
- var unansweredNote: LocalizedStringResource? {
- switch (unanswered.contains(.agent), unanswered.contains(.daemon)) {
+ var unansweredNote: LocalizedStringResource? { unanswered.missingJobsNote }
+}
+
+extension Set<BackgroundItem.Kind> {
+ /// What a page says when jobs of these kinds may be missing from it, or nil when there are none.
+ var missingJobsNote: LocalizedStringResource? {
+ switch (contains(.agent), contains(.daemon)) {
case (true, true): "macOS didn’t list the agents and daemons that apps added, so some may be missing here."
case (true, false): "macOS didn’t list the agents that apps added, so some may be missing here."
case (false, true): "macOS didn’t list the daemons that apps added, so some may be missing here."
diff --git a/Peel/Model/IntelLibrary.swift b/Peel/Model/IntelLibrary.swift
index 8243543f..ff72b65b 100644
--- a/Peel/Model/IntelLibrary.swift
+++ b/Peel/Model/IntelLibrary.swift
@@ -22,15 +22,15 @@ final class IntelLibrary {
/// Scans everything the report covers, so it is complete even when the other pages were never opened.
/// Plug-ins the Plug-ins page already found are reused, because that scan checks every plug-in's signature
/// and a Mac used for music can hold hundreds of them.
- func refresh(installedApps: [InstalledApp], revision: Int, plugins known: [Plugin]? = nil) async {
+ func refresh(installedApps: [InstalledApp], revision: Int, plugins known: PluginScan? = nil) async {
guard let result = await scanRun.run({
let exclusions = ExclusionsStore.shared.exclusions
async let backgroundItems = BackgroundItems.scan(exclusions: exclusions)
- let plugins = if let known { known } else { await Plugins.scan(exclusions: exclusions).plugins }
+ let plugins = if let known { known } else { await Plugins.scan(exclusions: exclusions) }
return await IntelInspector.scan(
installedApps: installedApps,
plugins: plugins,
- backgroundItems: backgroundItems.items,
+ backgroundItems: backgroundItems,
exclusions: exclusions
)
}) else { return }
diff --git a/Peel/Model/PluginLibrary.swift b/Peel/Model/PluginLibrary.swift
index 2d019703..5eb2429f 100644
--- a/Peel/Model/PluginLibrary.swift
+++ b/Peel/Model/PluginLibrary.swift
@@ -4,10 +4,11 @@ import PeelCore
@Observable
final class PluginLibrary {
- private(set) var plugins: [Plugin]?
- /// The folders the last scan couldn't read, which may hold plug-ins it didn't list.
- private(set) var unreadable: [URL] = []
- private(set) var needsFullDiskAccess = false
+ /// What the last scan found, and the folders it couldn't read, which may hold plug-ins it didn't list.
+ private(set) var scan: PluginScan?
+ var plugins: [Plugin]? { scan?.plugins }
+ var unreadable: [URL] { scan?.unreadable ?? [] }
+ var needsFullDiskAccess: Bool { scan?.needsFullDiskAccess ?? false }
/// The scan this page runs, which a newer one or the Stop button ends.
let scanRun = ScanRun()
var isScanning: Bool { scanRun.isRunning }
@@ -21,9 +22,7 @@ final class PluginLibrary {
func refresh() async {
guard let result = await scanRun.run({ await Plugins.scan(exclusions: ExclusionsStore.shared.exclusions) })
else { return }
- plugins = result.plugins
- unreadable = result.unreadable
- needsFullDiskAccess = result.needsFullDiskAccess
+ scan = result
if let selection, !result.plugins.contains(where: { $0.id == selection }) {
self.selection = nil
}
diff --git a/Peel/Views/Intel/IntelList.swift b/Peel/Views/Intel/IntelList.swift
index a9e3ef0d..6109f8e4 100644
--- a/Peel/Views/Intel/IntelList.swift
+++ b/Peel/Views/Intel/IntelList.swift
@@ -5,6 +5,7 @@ struct IntelList: View {
@Environment(IntelLibrary.self) private var intel
@Environment(PluginLibrary.self) private var plugins
@Environment(AppLibrary.self) private var library
+ @Environment(HomeModel.self) private var home
@State private var isRescanning = false
@State private var searchText = ""
@@ -23,6 +24,13 @@ struct IntelList: View {
) {}
.listRowSeparator(.hidden)
}
+ if !intel.findings.isEmpty, let unread = unreadParts {
+ Notice(title: Text("Not Everything Could Be Read"), detail: unread, kind: .note) {
+ unreadActions
+ }
+ .padding(.vertical, 6)
+ .listRowSeparator(.hidden)
+ }
ForEach(IntelFinding.Kind.allCases, id: \.self) { kind in
if let findings = byKind[kind] {
Section {
@@ -42,6 +50,14 @@ struct IntelList: View {
.scanState(phase(matching), isRescanning: isRescanning, scan: intel.scanRun) {
if !searchText.isEmpty, matching.isEmpty {
ContentUnavailableView.search(text: searchText)
+ } else if intel.findings.isEmpty, let unread = unreadParts {
+ ContentUnavailableView {
+ Label("Not Everything Could Be Read", systemImage: "exclamationmark.triangle")
+ } description: {
+ unread
+ } actions: {
+ unreadActions
+ }
} else if intel.findings.isEmpty {
ContentUnavailableView(
"Nothing Needs Rosetta",
@@ -54,7 +70,12 @@ struct IntelList: View {
}
.fadesInColumn(whenRowsChange: intel.scan?.findings.map(\.id))
.navigationTitle(Text(Tool.intel.title))
- .announcesScan(intel.isScanning, found: intel.summary, wasStopped: intel.scanRun.wasStopped)
+ .announcesScan(
+ intel.isScanning,
+ found: intel.summary,
+ couldNotLook: intel.findings.isEmpty && unreadParts != nil ? "Not Everything Could Be Read" : nil,
+ wasStopped: intel.scanRun.wasStopped
+ )
.toolbar {
ToolbarItem {
RescanButton(isRunning: $isRescanning, scan: intel.scanRun) {
@@ -79,7 +100,44 @@ struct IntelList: View {
}
private func scan() async {
- await intel.refresh(installedApps: library.apps, revision: library.revision, plugins: plugins.plugins)
+ await intel.refresh(installedApps: library.apps, revision: library.revision, plugins: plugins.scan)
+ }
+
+ /// What Peel couldn't read for this page: the apps the Applications list couldn't, and what the scan couldn't.
+ private var unread: [URL] {
+ library.unreadable + (intel.scan?.unreadable ?? [])
+ }
+
+ private var needsFullDiskAccess: Bool {
+ library.unreadableNeedsFullDiskAccess || intel.scan?.needsFullDiskAccess == true
+ }
+
+ /// What Peel couldn't read, a paragraph for each kind, or nil when it read everything.
+ private var unreadParts: Text? {
+ let paths = unread.map(\.abbreviatedPath)
+ let parts = (library.listOfFoldersUnreadable
+ ? [Text("Peel can’t read its list of app folders, so it didn’t look at the apps in the folders you added.")] : [])
+ + (paths.isEmpty
+ ? [] : [Text("Peel couldn’t read \(RemovalFailureAlert.listedItems(paths)), so something there may need Rosetta.")])
+ + (needsFullDiskAccess ? [Text("Give Peel Full Disk Access so it can read the folders macOS protects.")] : [])
+ + (intel.scan?.unansweredJobs.missingJobsNote.map { [Text($0)] } ?? [])
+ guard let first = parts.first else { return nil }
+ return parts.dropFirst().reduce(first) { Text("\($0)\n\n\($1)") }
+ }
+
+ @ViewBuilder
+ private var unreadActions: some View {
+ if library.listOfFoldersUnreadable {
+ Button("Start Over") { library.startFoldersOver() }
+ }
+ if needsFullDiskAccess {
+ if home.needsRelaunchForFullDiskAccess {
+ Button("Reopen Peel") { home.relaunch() }
+ }
+ Button("Open System Settings") { home.openFullDiskAccessSettings() }
+ } else if unread.count > RemovalFailureAlert.mostListed {
+ CopyButton(text: unread.map(\.abbreviatedPath).joined(separator: "\n"), title: "Copy Details")
+ }
}
}
diff --git a/Peel/Views/RemovalFailureAlert.swift b/Peel/Views/RemovalFailureAlert.swift
index 71ed3739..349b96cb 100644
--- a/Peel/Views/RemovalFailureAlert.swift
+++ b/Peel/Views/RemovalFailureAlert.swift
@@ -38,6 +38,11 @@ struct RemovalFailureAlert: ViewModifier {
listed(paths) { String(inflecting: "^[\($0) more folder](inflect: true)") }
}
+ /// Folders and files named in one sentence, the same way.
+ static func listedItems(_ paths: [String]) -> String {
+ listed(paths) { String(inflecting: "^[\($0) more item](inflect: true)") }
+ }
+
private static func listed(_ names: [String], others: (Int) -> String) -> String {
guard names.count > mostListed else { return names.formatted(.list(type: .and)) }
return (names.prefix(mostListed) + [others(names.count - mostListed)]).formatted(.list(type: .and))