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 which folder of job files Peel couldn't look in

Țugui Dragoș2d28950a7637
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index fef83899..947f93b6 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -114122,6 +114122,112 @@
}
}
},
+ "Peel can’t look in %@, so a job whose file is there shows here only while macOS has it loaded." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemůže nahlédnout do složky %@, takže úloha, jejíž soubor tam je, se tu zobrazí, jen dokud ji má systém macOS načtenou."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kann nicht in %@ hineinsehen, daher wird ein Job, dessen Datei dort liegt, hier nur angezeigt, solange macOS ihn geladen hat."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no puede mirar en %@, así que una tarea cuyo archivo esté ahí solo aparece aquí mientras macOS la tenga cargada."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel ne peut pas regarder dans %@ : une tâche dont le fichier s’y trouve n’apparaît donc ici que tant que macOS la garde chargée."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non riesce a esaminare %@, quindi un elemento il cui file si trova lì compare qui solo mentre macOS lo tiene caricato."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelは%@の中を調べられないため、そこにファイルがあるジョブは、macOSが読み込んでいる間しかここに表示されません。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel이 %@ 안을 살펴볼 수 없으므로, 파일이 그곳에 있는 작업은 macOS가 로드해 둔 동안에만 여기에 표시됩니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan niet in %@ kijken, dus een taak waarvan het bestand daar staat, wordt hier alleen getoond zolang macOS die taak heeft geladen."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie może zajrzeć do %@, więc zadanie, którego plik się tam znajduje, pojawia się tutaj tylko wtedy, gdy macOS ma je wczytane."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não consegue examinar o conteúdo de %@, então uma tarefa cujo arquivo está lá só aparece aqui enquanto o macOS a mantém carregada."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu poate căuta în %@, așa că o sarcină al cărei fișier se află acolo apare aici doar cât timp macOS o are încărcată."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не может заглянуть в %@, поэтому задание, файл которого находится там, показывается здесь, только пока оно загружено в macOS."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan inte titta i %@, så ett jobb vars fil finns där visas bara här medan macOS har det inläst."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel, %@ klasörünün içine bakamıyor, bu yüzden dosyası orada olan bir iş burada yalnızca macOS onu yüklü tuttuğu sürece görünür."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не може зазирнути в %@, тож завдання, файл якого лежить там, показується тут, лише поки macOS тримає його завантаженим."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel无法查看%@中的内容,因此文件位于其中的任务只在macOS已载入它时才会显示在这里。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel無法查看%@,因此檔案位於那裡的工作,只有在macOS已載入它時才會顯示在這裡。"
+ }
+ }
+ }
+ },
"Peel can’t look in the Trash right now" : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift b/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift
index 0d5157b3..1025b3f3 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift
@@ -331,27 +331,18 @@ public enum IntelInspector {
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) }
+ if let folder = FileAccess.refusedFolder(directory) { unreadable.append(folder) }
return []
}
return names.map { directory.appending(path: $0) }
}
- /// 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)
+ unreadable.append(
+ program.isThere ? program : FileAccess.refusedFolder(program.deletingLastPathComponent()) ?? program
+ )
}
/// Whether a file can be run by anyone: one that only root may run still runs, though Peel can't read it.
@@ -383,7 +374,9 @@ public enum IntelInspector {
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) }
+ if let folder = FileAccess.refusedFolder(candidate.deletingLastPathComponent()) {
+ unreadable.append(folder)
+ }
return nil
}
}
@@ -407,14 +400,14 @@ public enum IntelInspector {
return true
}
) else {
- if let folder = refusedFolder(url) { unreadable.append(folder) }
+ if let folder = FileAccess.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) }
}
- unreadable += refused.compactMap(refusedFolder)
+ unreadable += refused.compactMap(FileAccess.refusedFolder)
}
return bundles
}
@@ -434,7 +427,7 @@ public enum IntelInspector {
return true
}
) else {
- if let folder = refusedFolder(url) { unreadable.append(folder) }
+ if let folder = FileAccess.refusedFolder(url) { unreadable.append(folder) }
continue
}
for case let item as URL in enumerator {
@@ -454,7 +447,7 @@ public enum IntelInspector {
case false?: break
}
}
- unreadable += refused.compactMap(refusedFolder)
+ unreadable += refused.compactMap(FileAccess.refusedFolder)
}
return programs
}
@@ -471,7 +464,7 @@ public enum IntelInspector {
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()) {
+ let place = FileAccess.refusedFolder(program.deletingLastPathComponent()) {
unreadable.append(place)
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift
index 6843d27f..f1af9207 100644
--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift
+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift
@@ -1,5 +1,5 @@
import Darwin
-import Foundation
+public import Foundation
import PeelPrivileged
public enum BackgroundItems {
@@ -10,10 +10,16 @@ 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>
+ /// The folders that kept Peel from listing a folder of job files, so a job whose file is there and which isn't
+ /// loaded is missing.
+ public let unreadableFolders: [URL]
- public init(items: [BackgroundItem] = [], unanswered: Set<BackgroundItem.Kind> = []) {
+ public init(
+ items: [BackgroundItem] = [], unanswered: Set<BackgroundItem.Kind> = [], unreadableFolders: [URL] = []
+ ) {
self.items = items
self.unanswered = unanswered
+ self.unreadableFolders = unreadableFolders
}
}
@@ -77,34 +83,76 @@ public enum BackgroundItems {
return results
}
let undeclared = merged(found, loaded: loaded)
- items = placing(undeclared.items, into: items)
+ let unlisted = unlistedJobFolders(in: environment, exclusions: exclusions)
+ items = placing(undeclared.items, into: items, unlisted: unlisted.map { ($0.folder, $0.source) })
items += disabledJobs(in: loaded, listed: items, ownership: ownership)
return Scan(
items: items
.filter { $0.ownerBundleIdentifier.map(exclusions.excludes(bundleIdentifier:)) != true }
.sorted { $0.label.localizedStandardCompare($1.label) == .orderedAscending },
- unanswered: undeclared.unanswered
+ unanswered: undeclared.unanswered,
+ unreadableFolders: unlisted.map(\.refused).reduce(into: []) { if !$0.contains($1) { $0.append($1) } }
)
}
/// The rows, each job launchd loaded from a file Peel can't read in the place of that file's row, with the file's
/// folder as its source; then the other loaded jobs.
- static func placing(_ loadedJobs: [BackgroundItem], into rows: [BackgroundItem]) -> [BackgroundItem] {
+ private static func jobFolders(
+ in environment: SearchEnvironment
+ ) -> [(folder: URL, kind: BackgroundItem.Kind, source: BackgroundItem.Source)] {
+ let userLibrary = environment.homeDirectory.appending(path: "Library", directoryHint: .isDirectory)
+ let systemLibrary = environment.rootDirectory.appending(path: "Library", directoryHint: .isDirectory)
+ return [
+ (userLibrary.appending(path: "LaunchAgents", directoryHint: .isDirectory), .agent, .userLibrary),
+ (systemLibrary.appending(path: "LaunchAgents", directoryHint: .isDirectory), .agent, .systemLibrary),
+ (systemLibrary.appending(path: "LaunchDaemons", directoryHint: .isDirectory), .daemon, .systemLibrary),
+ ]
+ }
+
+ /// The folders of the three that Peel can't list, each with where its jobs come from and the folder that kept Peel
+ /// out, which can be one around it.
+ static func unlistedJobFolders(
+ in environment: SearchEnvironment, exclusions: Exclusions = .none
+ ) -> [(folder: URL, source: BackgroundItem.Source, refused: URL)] {
+ jobFolders(in: environment).compactMap { folder, _, source in
+ guard !exclusions.excludes(folder),
+ (try? FileManager.default.contentsOfDirectory(atPath: folder.path(percentEncoded: false))) == nil,
+ let refused = FileAccess.refusedFolder(folder)
+ else { return nil }
+ return (folder, source, refused)
+ }
+ }
+
+ /// The rows, each job launchd loaded from a file Peel can't read in the place of that file's row, with the file's
+ /// folder as its source; then the other loaded jobs, one from a folder Peel can't list with that folder's source.
+ static func placing(
+ _ loadedJobs: [BackgroundItem],
+ into rows: [BackgroundItem],
+ unlisted: [(folder: URL, source: BackgroundItem.Source)] = []
+ ) -> [BackgroundItem] {
var rows = rows
var others: [BackgroundItem] = []
for job in loadedJobs {
- let file = job.plistURL.map(PathPattern.comparablePath(of:))
- guard let file, let index = rows.firstIndex(where: {
- $0.isClosedToPeel && $0.isNamedByItsFile && $0.plistURL.map(PathPattern.comparablePath(of:)) == file
- }) else {
+ guard let plist = job.plistURL else {
others.append(job)
continue
}
+ let file = PathPattern.comparablePath(of: plist)
+ let folder = PathPattern.comparablePath(of: plist.deletingLastPathComponent())
var placed = job
- placed.source = rows[index].source
placed.isClosedToPeel = true
- rows[index] = placed
+ if let index = rows.firstIndex(where: {
+ $0.isClosedToPeel && $0.isNamedByItsFile && $0.plistURL.map(PathPattern.comparablePath(of:)) == file
+ }) {
+ placed.source = rows[index].source
+ rows[index] = placed
+ } else if let unlisted = unlisted.first(where: { PathPattern.comparablePath(of: $0.folder) == folder }) {
+ placed.source = unlisted.source
+ others.append(placed)
+ } else {
+ others.append(job)
+ }
}
return rows + others
}
@@ -238,16 +286,8 @@ public enum BackgroundItems {
exclusions: Exclusions = .none,
loaded: Loaded = Loaded()
) -> [BackgroundItem] {
- let userLibrary = environment.homeDirectory.appending(path: "Library", directoryHint: .isDirectory)
- let systemLibrary = environment.rootDirectory.appending(path: "Library", directoryHint: .isDirectory)
- let folders: [(URL, BackgroundItem.Kind, BackgroundItem.Source)] = [
- (userLibrary.appending(path: "LaunchAgents", directoryHint: .isDirectory), .agent, .userLibrary),
- (systemLibrary.appending(path: "LaunchAgents", directoryHint: .isDirectory), .agent, .systemLibrary),
- (systemLibrary.appending(path: "LaunchDaemons", directoryHint: .isDirectory), .daemon, .systemLibrary),
- ]
-
var items: [BackgroundItem] = []
- for (folder, kind, source) in folders {
+ for (folder, kind, source) in jobFolders(in: environment) {
for plist in plists(in: folder) where !exclusions.excludes(plist) {
// A label of macOS's own is shown too, and marked (`usesALabelOfMacOS`): macOS keeps its jobs
// elsewhere, so a file here that borrows one is somebody else's, and a common way to hide a job.
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/FileAccess.swift b/Packages/PeelCore/Sources/PeelCore/Support/FileAccess.swift
index 69604263..e4b7ce5c 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/FileAccess.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/FileAccess.swift
@@ -25,6 +25,18 @@ public enum FileAccess {
access(url.path(percentEncoded: false), R_OK) != 0 && (errno == EACCES || errno == EPERM)
}
+ /// 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)
+ }
+
static func isARealFolder(_ url: URL) -> Bool {
var info = stat()
return lstat(url.path(percentEncoded: false), &info) == 0 && info.st_mode & S_IFMT == S_IFDIR
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift
index e0516946..44acab69 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift
@@ -718,6 +718,33 @@ struct DeclaredBackgroundItemsTests {
#expect(rows.last?.source == .otherFile && rows.last?.isClosedToPeel == false)
}
+ @Test(.permissionsHold) func namesAJobFolderPeelCannotLookIn() throws {
+ let directory = try TemporaryDirectory()
+ try directory.directory("home/Library/LaunchAgents")
+ try directory.setPermissions(0, of: "home/Library/LaunchAgents")
+ defer { try? directory.setPermissions(0o755, of: "home/Library/LaunchAgents") }
+
+ let unlisted = BackgroundItems.unlistedJobFolders(in: environment(directory))
+
+ #expect(unlisted.map(\.refused.lastPathComponent) == ["LaunchAgents"], "a folder that isn't there hides nothing")
+ #expect(unlisted.first?.source == .userLibrary)
+ }
+
+ @Test func aJobLoadedFromAFolderPeelCannotLookInComesFromThatFolder() {
+ let folder = URL(filePath: "/org.example/home/Library/LaunchAgents", directoryHint: .isDirectory)
+ let job = BackgroundItem(
+ label: "org.example.agent", kind: .agent, source: .otherFile,
+ plistURL: folder.appending(path: "org.example.agent.plist"), program: "/bin/sh", runsAtLoad: nil,
+ keepsAlive: nil, ownerBundleIdentifier: nil, ownerName: nil, ownerURL: nil, isOrphan: false,
+ state: .running(pid: 7), isDisabled: false
+ )
+
+ let rows = BackgroundItems.placing([job], into: [], unlisted: [(folder, .userLibrary)])
+
+ #expect(rows.first?.source == .userLibrary, "launchd loaded it from its own folder, not from elsewhere")
+ #expect(rows.first?.isClosedToPeel == true)
+ }
+
/// macOS keeps its own jobs under `/System/Library` and `/Library/Apple/System/Library`, so a file in these
/// folders that uses one of their labels, or any `com.apple.` label, is not macOS's. A label names a job only
/// in its own domain, so such a copy runs beside the real one: it is listed, marked, and never acted on.
diff --git a/Peel/Model/BackgroundItemLibrary.swift b/Peel/Model/BackgroundItemLibrary.swift
index 9360aad7..eb9e5e1c 100644
--- a/Peel/Model/BackgroundItemLibrary.swift
+++ b/Peel/Model/BackgroundItemLibrary.swift
@@ -7,6 +7,8 @@ final class BackgroundItemLibrary {
private(set) var items: [BackgroundItem]?
/// The kinds of job some of which may be missing, because macOS answered about them in a form Peel cannot read.
private(set) var unanswered: Set<BackgroundItem.Kind> = []
+ /// The folders that kept Peel from listing a folder of job files.
+ private(set) var unreadableFolders: [URL] = []
/// The scan this page runs, which a newer one or the Stop button ends.
let scanRun = ScanRun()
var isScanning: Bool { scanRun.isRunning }
@@ -74,6 +76,7 @@ final class BackgroundItemLibrary {
private func show(_ result: BackgroundItems.Scan, read: Int) {
items = result.items
unanswered = result.unanswered
+ unreadableFolders = result.unreadableFolders
scans += 1
if let selection, items?.contains(where: { $0.id == selection }) != true {
self.selection = nil
@@ -159,8 +162,14 @@ 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? { unanswered.missingJobsNote }
+ /// What the page says when some jobs may be missing, a paragraph for each reason, or nil when none is.
+ var missingNote: String? {
+ let parts = (unanswered.missingJobsNote.map { [String(localized: $0)] } ?? [])
+ + unreadableFolders.map {
+ String(localized: "Peel can’t look in \($0.abbreviatedPath), so a job whose file is there shows here only while macOS has it loaded.")
+ }
+ return parts.isEmpty ? nil : parts.joined(separator: "\n\n")
+ }
}
extension Set<BackgroundItem.Kind> {
diff --git a/Peel/Views/BackgroundItems/BackgroundItemList.swift b/Peel/Views/BackgroundItems/BackgroundItemList.swift
index 4cfd6305..231823b7 100644
--- a/Peel/Views/BackgroundItems/BackgroundItemList.swift
+++ b/Peel/Views/BackgroundItems/BackgroundItemList.swift
@@ -12,8 +12,8 @@ struct BackgroundItemList: View {
let filtered = filteredItems
List(selection: $backgroundItems.selection) {
- if let note = backgroundItems.unansweredNote, !filtered.isEmpty {
- Notice(title: Text("Part of this list may be missing"), detail: Text(note), kind: .note) {}
+ if let note = backgroundItems.missingNote, !filtered.isEmpty {
+ Notice(title: Text("Part of this list may be missing"), detail: Text(verbatim: note), kind: .note) {}
.padding(.vertical, 6)
.listRowSeparator(.hidden)
}
@@ -23,12 +23,17 @@ struct BackgroundItemList: View {
.accessibilityLabel(Text(Tool.backgroundItems.title))
.scrollBarBelowSectionHeaders(!filtered.isEmpty)
.scanState(phase(filtered), isRescanning: isRescanning, scan: backgroundItems.scanRun) {
- if let note = backgroundItems.unansweredNote, backgroundItems.items?.isEmpty == true {
- ContentUnavailableView(
- "macOS Didn’t Answer",
- systemImage: "exclamationmark.triangle",
- description: Text(note)
- )
+ if backgroundItems.items?.isEmpty == true,
+ let note = backgroundItems.missingNote, let title = couldNotLook {
+ ContentUnavailableView {
+ Label {
+ Text(title)
+ } icon: {
+ Image(systemName: "exclamationmark.triangle")
+ }
+ } description: {
+ Text(verbatim: note)
+ }
} else if backgroundItems.items?.isEmpty == true {
ContentUnavailableView(
"No Background Items",
@@ -45,7 +50,7 @@ struct BackgroundItemList: View {
.announcesScan(
backgroundItems.isScanning,
found: backgroundItems.summary,
- couldNotLook: backgroundItems.unanswered.isEmpty ? nil : "macOS Didn’t Answer",
+ couldNotLook: couldNotLook,
wasStopped: backgroundItems.scanRun.wasStopped
)
.toolbar {
@@ -85,6 +90,11 @@ struct BackgroundItemList: View {
}
}
+ private var couldNotLook: LocalizedStringResource? {
+ if !backgroundItems.unanswered.isEmpty { return "macOS Didn’t Answer" }
+ return backgroundItems.unreadableFolders.isEmpty ? nil : "Not Everything Could Be Read"
+ }
+
private func phase(_ filtered: [BackgroundItem]) -> ScanPhase {
if backgroundItems.items == nil { return backgroundItems.scanRun.wasStopped ? .stopped : .scanning(.walk) }
if backgroundItems.items?.isEmpty == true { return .message }