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 plainly when Peel can't read its list of app folders

Țugui Dragoș5eb289cfbab2
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
index a8743be7..75990ac1 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
@@ -157,10 +157,12 @@ struct OrphansCommand: AsyncParsableCommand {
/// Why nothing is listed when some apps could not be read: their files would look orphaned.
static func refusal(for catalog: AppScan) -> CommandFailure? {
- guard !catalog.unreadable.isEmpty else { return nil }
- let listed = Output.list(catalog.unreadable.map { Output.plain(Output.path($0)) })
+ guard !catalog.readEverything else { return nil }
+ let list = catalog.listOfFoldersUnreadable ? ["its list of app folders"] : []
+ let listed = Output.list(list + catalog.unreadable.map { Output.plain(Output.path($0)) })
let access = catalog.needsFullDiskAccess ? " Give your terminal app Full Disk Access in System Settings." : ""
- return CommandFailure("Peel couldn't read \(listed), so it can't tell which apps are installed. Nothing is listed, since the files of an app it can't see would look orphaned.\(access)")
+ let startOver = list.isEmpty ? "" : " Start the list over in Settings > General > App Folders."
+ return CommandFailure("Peel couldn't read \(listed), so it can't tell which apps are installed. Nothing is listed, since the files of an app it can't see would look orphaned.\(access)\(startOver)")
}
static func report(for scan: OrphanScan) -> Report {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index 65a26460..6adae526 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -196,8 +196,14 @@ enum Output {
/// What a reading of the apps could not read, so the apps in it are missing from what is written, or nil when it
/// read everything.
static func unreadableNote(for catalog: AppScan) -> String? {
- guard !catalog.unreadable.isEmpty else { return nil }
- return unreadableNote(for: catalog.unreadable, needsFullDiskAccess: catalog.needsFullDiskAccess)
+ var notes: [String] = []
+ if catalog.listOfFoldersUnreadable {
+ notes.append("Peel can't read its list of app folders, so the apps in them aren't listed. Start it over in Settings > General > App Folders.")
+ }
+ if !catalog.unreadable.isEmpty {
+ notes.append(unreadableNote(for: catalog.unreadable, needsFullDiskAccess: catalog.needsFullDiskAccess))
+ }
+ return notes.isEmpty ? nil : notes.joined(separator: "\n")
}
/// Whether the user can answer a question about the plan printed above it: standard input, standard output and
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppCatalog.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppCatalog.swift
index 535f0753..56781f55 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppCatalog.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppCatalog.swift
@@ -5,11 +5,24 @@ import Synchronization
/// One reading of the folders apps are kept in.
public struct AppScan: Sendable, Equatable {
public let apps: [InstalledApp]
- /// What is there and could not be read: a folder of apps, an app, or the list of folders the person chose. The
- /// apps in it are missing from `apps`, so nothing can be called orphaned while this is not empty.
+ /// What is there and could not be read: a folder of apps or an app, whose apps are missing from `apps`.
public let unreadable: [URL]
/// Whether Full Disk Access would open what could not be read.
public let needsFullDiskAccess: Bool
+ /// Whether the list of folders the person chose is there and could not be read, so the apps in those folders are
+ /// missing from `apps` too. Settings > General > App Folders starts it over.
+ public let listOfFoldersUnreadable: Bool
+
+ init(apps: [InstalledApp], unreadable: [URL], needsFullDiskAccess: Bool, listOfFoldersUnreadable: Bool = false) {
+ self.apps = apps
+ self.unreadable = unreadable
+ self.needsFullDiskAccess = needsFullDiskAccess
+ self.listOfFoldersUnreadable = listOfFoldersUnreadable
+ }
+
+ /// Whether every app could be read. Until then nothing can be called orphaned, since the files of an app Peel
+ /// can't see would look so.
+ public var readEverything: Bool { unreadable.isEmpty && !listOfFoldersUnreadable }
}
public enum AppCatalog {
@@ -74,15 +87,16 @@ public enum AppCatalog {
}
/// Reads the apps in the Applications folders and in the folders the person chose. When the list of chosen
- /// folders cannot be read, the list itself is among what could not be read.
+ /// folders cannot be read, the reading says so (`listOfFoldersUnreadable`).
@concurrent
public static func scan(choices: AppFolders = AppFolders()) async -> AppScan {
guard let chosen = choices.load() else {
let standard = await scan(in: standardDirectories)
return AppScan(
apps: standard.apps,
- unreadable: standard.unreadable + [choices.url],
- needsFullDiskAccess: standard.needsFullDiskAccess
+ unreadable: standard.unreadable,
+ needsFullDiskAccess: standard.needsFullDiskAccess,
+ listOfFoldersUnreadable: true
)
}
return await scan(in: directories(adding: chosen))
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
index 4c0e2bc2..6602e53a 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
@@ -247,13 +247,14 @@ struct AppInspectorTests {
#expect(scan.unreadable.map(\.lastPathComponent) == ["Closed", "Sealed.app"])
}
- @Test func aListOfFoldersThatCannotBeReadIsAmongWhatWasNotRead() async throws {
+ @Test func aListOfFoldersThatCannotBeReadIsSaidApart() async throws {
let directory = try TemporaryDirectory()
let list = try directory.file("app-folders.json", contents: Data("not a list".utf8))
let scan = await AppCatalog.scan(choices: AppFolders(url: list))
- #expect(scan.unreadable.contains(list))
+ #expect(scan.listOfFoldersUnreadable && !scan.readEverything)
+ #expect(!scan.unreadable.contains(list))
}
/// Launch Services would answer Loud Name, and asking it registers the bundle.
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
index 1836b623..c5b1518b 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
@@ -31,6 +31,8 @@ struct CommandLineTests {
Output.unreadableNote(for: AppScan(apps: [], unreadable: [studio], needsFullDiskAccess: false))
== "Peel couldn't look inside /Volumes/Studio/Apps, so something may be there that isn't listed."
)
+ let listUnread = AppScan(apps: [], unreadable: [], needsFullDiskAccess: false, listOfFoldersUnreadable: true)
+ #expect(Output.unreadableNote(for: listUnread) == "Peel can't read its list of app folders, so the apps in them aren't listed. Start it over in Settings > General > App Folders.")
}
/// An app the terminal can't move for want of App Management needs no administrator, so the command names the
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
index beda0b7c..f084ce08 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
@@ -637,6 +637,8 @@ struct FileCommandTests {
#expect(refusal?.description == "Peel couldn't read /Volumes/Studio/Apps, so it can't tell which apps are installed. Nothing is listed, since the files of an app it can't see would look orphaned.")
let locked = OrphansCommand.refusal(for: AppScan(apps: [], unreadable: [studio], needsFullDiskAccess: true))
#expect(locked?.description.hasSuffix(" Give your terminal app Full Disk Access in System Settings.") == true)
+ let list = AppScan(apps: [], unreadable: [], needsFullDiskAccess: false, listOfFoldersUnreadable: true)
+ #expect(OrphansCommand.refusal(for: list)?.description == "Peel couldn't read its list of app folders, so it can't tell which apps are installed. Nothing is listed, since the files of an app it can't see would look orphaned. Start the list over in Settings > General > App Folders.")
}
/// A chosen folder Peel didn't look in, such as a repository, is said, so an empty answer is not read as none.
diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swift
index ff8a264e..0bfa7507 100644
--- a/Peel/Model/AppLibrary.swift
+++ b/Peel/Model/AppLibrary.swift
@@ -76,6 +76,11 @@ final class AppLibrary {
private(set) var unreadable: [URL] = []
/// Whether Full Disk Access would open what the last reading could not read.
private(set) var unreadableNeedsFullDiskAccess = false
+ /// Whether the last reading could not read the list of chosen folders (`AppScan.listOfFoldersUnreadable`).
+ private(set) var listOfFoldersUnreadable = false
+
+ /// Whether the last reading read every app, which Orphaned Files waits for.
+ var readEverything: Bool { listing.readEverything }
private(set) var updateStatuses: [InstalledApp.ID: UpdateStatus] = [:] {
didSet { updatesRevision += 1 }
}
@@ -197,10 +202,13 @@ final class AppLibrary {
struct Listing: Equatable {
let revision: Int
let unreadable: [URL]
+ let listOfFoldersUnreadable: Bool
+
+ var readEverything: Bool { unreadable.isEmpty && !listOfFoldersUnreadable }
}
var listing: Listing {
- Listing(revision: revision, unreadable: unreadable)
+ Listing(revision: revision, unreadable: unreadable, listOfFoldersUnreadable: listOfFoldersUnreadable)
}
/// The first reading of the folders, at launch. A reading the folder watch starts meanwhile takes its place
@@ -310,6 +318,9 @@ final class AppLibrary {
private func keepUnreadable(of scan: AppScan) {
if unreadable != scan.unreadable { unreadable = scan.unreadable }
+ if listOfFoldersUnreadable != scan.listOfFoldersUnreadable {
+ listOfFoldersUnreadable = scan.listOfFoldersUnreadable
+ }
if unreadableNeedsFullDiskAccess != scan.needsFullDiskAccess {
unreadableNeedsFullDiskAccess = scan.needsFullDiskAccess
}
diff --git a/Peel/Model/OrphanLibrary.swift b/Peel/Model/OrphanLibrary.swift
index 930c998a..fc832737 100644
--- a/Peel/Model/OrphanLibrary.swift
+++ b/Peel/Model/OrphanLibrary.swift
@@ -43,7 +43,7 @@ final class OrphanLibrary {
// An app that could not be read is missing from the list, and its files would look orphaned, so nothing is
// listed until every app can be read.
let listing = library.listing
- guard listing.unreadable.isEmpty else {
+ guard listing.readEverything else {
scan = nil
selection = nil
selectedURLs = []
@@ -72,7 +72,7 @@ final class OrphanLibrary {
await AppMemory().remember(scan.appsOnOtherDisks)
}
return scan
- }), library.unreadable.isEmpty else { return }
+ }), library.readEverything else { return }
let remainingURLs = Set(result.groups.flatMap(\.items).filter { $0.leftAlone == nil }.map(\.url))
scan = result
scannedAgainst = listing
diff --git a/Peel/Views/AppList.swift b/Peel/Views/AppList.swift
index da9d38d7..00d4656c 100644
--- a/Peel/Views/AppList.swift
+++ b/Peel/Views/AppList.swift
@@ -19,6 +19,17 @@ struct AppList: View {
if let problem = library.teamRecordProblem {
TeamRecordNotice(problem: problem)
}
+ if library.listOfFoldersUnreadable {
+ Notice(
+ title: Text("App Folders"),
+ detail: Text("Peel can’t read its list of app folders, so Orphaned Files lists nothing. Starting over keeps the old list beside a new one."),
+ kind: .note
+ ) {
+ Button("Start Over") { library.startFoldersOver() }
+ }
+ .padding(.vertical, 6)
+ .listRowSeparator(.hidden)
+ }
if library.unreadableNeedsFullDiskAccess {
FullDiskAccessBanner()
} else if !library.unreadable.isEmpty {
diff --git a/Peel/Views/Orphans/OrphanList.swift b/Peel/Views/Orphans/OrphanList.swift
index fd6a0eb4..b5794b06 100644
--- a/Peel/Views/Orphans/OrphanList.swift
+++ b/Peel/Views/Orphans/OrphanList.swift
@@ -39,18 +39,21 @@ struct OrphanList: View {
}
}
.scanState(phase(filtered, forAnAdministrator), isRescanning: isRescanning, scan: orphans.scanRun) {
- if !library.unreadable.isEmpty {
+ if !library.readEverything {
ContentUnavailableView {
Label("Not Every App Could Be Read", systemImage: "exclamationmark.triangle")
} description: {
+ let list = Text("Peel can’t read its list of app folders, so Orphaned Files lists nothing. Starting over keeps the old list beside a new one.")
let unread = Text("Peel couldn’t read \(library.unreadable.map(\.abbreviatedPath).formatted(.list(type: .and))), so it can’t tell which apps are installed. Nothing is listed here, since the files of an app it can’t see would look orphaned.")
- if library.unreadableNeedsFullDiskAccess {
- let access = Text("Give Peel Full Disk Access so it can read the folders macOS protects.")
- Text("\(unread)\n\n\(access)")
- } else {
- unread
- }
+ let access = Text("Give Peel Full Disk Access so it can read the folders macOS protects.")
+ let parts = (library.listOfFoldersUnreadable ? [list] : [])
+ + (library.unreadable.isEmpty ? [] : [unread])
+ + (library.unreadableNeedsFullDiskAccess ? [access] : [])
+ parts.dropFirst().reduce(parts.first ?? Text(verbatim: "")) { Text("\($0)\n\n\($1)") }
} actions: {
+ if library.listOfFoldersUnreadable {
+ Button("Start Over") { library.startFoldersOver() }
+ }
if library.unreadableNeedsFullDiskAccess {
Button("Open System Settings") { home.openFullDiskAccessSettings() }
}
@@ -98,7 +101,7 @@ struct OrphanList: View {
.announcesScan(
orphans.isScanning,
found: orphans.summary,
- couldNotLook: !library.unreadable.isEmpty ? "Not Every App Could Be Read"
+ couldNotLook: !library.readEverything ? "Not Every App Could Be Read"
: orphans.scan?.unreadableLocations.isEmpty == false ? "Not Everything Could Be Read" : nil,
wasStopped: orphans.scanRun.wasStopped
)
@@ -122,7 +125,7 @@ struct OrphanList: View {
scan: orphans.scanRun
) {
// What could not be read may be readable now, so the apps are read again first.
- if !library.unreadable.isEmpty {
+ if !library.readEverything {
await library.checkAgain(await library.refresh())
}
await orphans.refresh(from: library)
@@ -142,7 +145,7 @@ struct OrphanList: View {
}
private func phase(_ filtered: [OrphanGroup], _ forAnAdministrator: [AdministratorItem]) -> ScanPhase {
- if !library.unreadable.isEmpty { return .message }
+ if !library.readEverything { return .message }
if orphans.scan == nil { return orphans.scanRun.wasStopped ? .stopped : .scanning(.walk) }
if listsNothing { return .message }
if filtered.isEmpty, forAnAdministrator.isEmpty, !searchText.isEmpty { return .message }