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 why the list of app folders couldn't be read or saved

Țugui Dragoș8e93f1c776a6
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
index 6ca56b33..e80e4cc2 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
@@ -187,7 +187,8 @@ struct OrphansCommand: AsyncParsableCommand {
let listed = Output.list(list + Output.named(catalog.unreadable))
let why = Output.whyNotRead(catalog.unreadable).map { " " + $0 } ?? ""
let access = catalog.needsFullDiskAccess ? " " + Output.fullDiskAccessAdvice : ""
- let startOver = list.isEmpty ? "" : " Start the list over in Settings > General > App Folders."
+ let startOver = list.isEmpty
+ ? "" : " Start the list over in Settings > General > App Folders." + catalog.whyListOfFoldersUnreadable.sentence
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.\(why)\(access)\(startOver)")
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index dc62f36e..9cd81a24 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -217,7 +217,7 @@ enum Output {
static func unreadableNote(for catalog: AppScan) -> String? {
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.")
+ 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." + catalog.whyListOfFoldersUnreadable.sentence)
}
if !catalog.unreadable.isEmpty {
notes.append(unreadableNote(for: catalog.unreadable, needsFullDiskAccess: catalog.needsFullDiskAccess))
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppCatalog.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppCatalog.swift
index 2f1d8b5b..4e550ee4 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppCatalog.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppCatalog.swift
@@ -12,17 +12,20 @@ public struct AppScan: Sendable, Equatable {
/// The folders the person chose that the reading looked in, beside the Applications folders, or nil when their
/// list is there and could not be read.
public let chosenFolders: [URL]?
+ /// Why their list could not be read, when Peel knows.
+ public let whyListOfFoldersUnreadable: FileProblem?
/// The folders on that list it no longer reads, whose apps it doesn't list.
public let foldersLeftOut: [AppFolders.LeftOut]
init(
apps: [InstalledApp], unreadable: [URL] = [], needsFullDiskAccess: Bool = false, chosenFolders: [URL]? = [],
- foldersLeftOut: [AppFolders.LeftOut] = []
+ whyListOfFoldersUnreadable: FileProblem? = nil, foldersLeftOut: [AppFolders.LeftOut] = []
) {
self.apps = apps
self.unreadable = unreadable
self.needsFullDiskAccess = needsFullDiskAccess
self.chosenFolders = chosenFolders
+ self.whyListOfFoldersUnreadable = whyListOfFoldersUnreadable
self.foldersLeftOut = foldersLeftOut
}
@@ -107,6 +110,7 @@ public enum AppCatalog {
unreadable: found.unreadable,
needsFullDiskAccess: found.needsFullDiskAccess,
chosenFolders: chosen,
+ whyListOfFoldersUnreadable: chosen == nil ? choices.whyUnreadable() : nil,
foldersLeftOut: choices.leftOut()
)
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppFolders.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppFolders.swift
index 4a66df07..e9ea2802 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppFolders.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppFolders.swift
@@ -52,6 +52,19 @@ public struct AppFolders: Sendable {
FileLock.whileReading(beside: url) { url.isMissing ? [] : read() }
}
+ /// Why the saved list can't be read, asked again once `load()` found it couldn't: nil when it can, or isn't there.
+ public func whyUnreadable() -> FileProblem? {
+ FileLock.whileReading(beside: url) { url.isMissing ? nil : readProblem() }
+ }
+
+ /// What a change of the list did. A list that is there and can't be read is never written over, since that would
+ /// lose the folders it holds.
+ public enum Change: Sendable, Equatable {
+ case saved
+ /// And why, when Peel knows.
+ case notSaved(FileProblem?)
+ }
+
/// The folders the list holds that are no longer read, and why. One Peel reads anyway, as part of an Applications
/// folder, loses nothing.
public func leftOut() -> [LeftOut] {
@@ -65,10 +78,8 @@ public struct AppFolders: Sendable {
}
}
- /// Adds `folders`. False when they could not be saved, or when the file is there and cannot be read, since
- /// writing over it would lose the folders it holds.
@discardableResult
- public func add(_ folders: [URL]) -> Bool {
+ public func add(_ folders: [URL]) -> Change {
change { paths in
for path in folders.map({ PathPattern.comparablePath(of: $0) }) where !paths.contains(path) {
paths.append(path)
@@ -86,7 +97,7 @@ public struct AppFolders: Sendable {
}
@discardableResult
- public func remove(_ folders: [URL]) -> Bool {
+ public func remove(_ folders: [URL]) -> Change {
let removed = Set(folders.map { PathPattern.comparablePath(of: $0) })
return change { paths in
paths.removeAll { removed.contains(PathPattern.comparablePath(of: URL(filePath: $0))) }
@@ -142,15 +153,25 @@ public struct AppFolders: Sendable {
PathPattern.comparablePath(of: url).lowercased()
}
- private func change(_ edit: (inout [String]) -> Void) -> Bool {
+ private func change(_ edit: (inout [String]) -> Void) -> Change {
FileLock.whileHeld(beside: url) {
- guard var paths = saved() ?? (url.isMissing ? [] : nil) else { return false }
+ guard var paths = saved() ?? (url.isMissing ? [] : nil) else { return .notSaved(readProblem()) }
edit(&paths)
- guard let data = try? JSONEncoder().encode(paths) else { return false }
- return (try? PeelFolder.write(data, to: url)) != nil
+ do {
+ try PeelFolder.write(try JSONEncoder().encode(paths), to: url)
+ return .saved
+ } catch {
+ return .notSaved(.failed(SystemError(error)))
+ }
}
}
+ /// Why the list there can't be read, or nil when it can, for a caller that holds the lock.
+ private func readProblem() -> FileProblem? {
+ guard let data = BoundedRead.data(at: url) else { return BoundedRead.whyUnreadable(url) }
+ return (try? JSONDecoder().decode([String].self, from: data)) == nil ? .damaged : nil
+ }
+
/// The paths as saved, or nil when the file cannot be read.
private func saved() -> [String]? {
BoundedRead.data(at: url).flatMap { try? JSONDecoder().decode([String].self, from: $0) }
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppFoldersTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppFoldersTests.swift
index 3254f9e3..e939faca 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AppFoldersTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppFoldersTests.swift
@@ -133,11 +133,11 @@ struct AppFoldersTests {
let backup = URL(filePath: "/Volumes/Backup", directoryHint: .isDirectory)
#expect(folders.leftOut() == [AppFolders.LeftOut(folder: backup, refusal: .tooBroad)])
- #expect(folders.add([other]))
+ #expect(folders.add([other]) == .saved)
#expect(folders.leftOut().map(\.refusal) == [.tooBroad], "an edit lost it without a word")
#expect(folders.load()?.map(\.lastPathComponent) == ["Tools", "Other"])
- #expect(folders.remove([URL(filePath: "/Volumes/Backup")]))
+ #expect(folders.remove([URL(filePath: "/Volumes/Backup")]) == .saved)
#expect(folders.leftOut().isEmpty)
}
@@ -181,12 +181,12 @@ struct AppFoldersTests {
let studio = directory.url.appending(path: "Studio Apps", directoryHint: .isDirectory)
#expect(folders.load() == [])
- #expect(folders.add([studio]))
+ #expect(folders.add([studio]) == .saved)
#expect(folders.load()?.map(\.lastPathComponent) == ["Studio Apps"])
let chosen = try #require(folders.load())
#expect(AppCatalog.directories(adding: chosen).count == AppCatalog.standardDirectories.count + 1)
- #expect(folders.remove([studio]))
+ #expect(folders.remove([studio]) == .saved)
#expect(folders.load() == [])
}
@@ -200,6 +200,24 @@ struct AppFoldersTests {
#expect(AppFolders(url: damaged).load() == nil)
#expect(AppFolders(url: closed).load() == nil)
#expect(AppFolders(url: directory.url.appending(path: "missing.json")).load() == [])
+
+ let closedRead = FileProblem.failed(SystemError(domain: NSPOSIXErrorDomain, code: Int(EACCES)))
+ #expect(AppFolders(url: damaged).whyUnreadable() == .damaged)
+ #expect(AppFolders(url: closed).whyUnreadable() == closedRead)
+ #expect(AppFolders(url: directory.url.appending(path: "missing.json")).whyUnreadable() == nil)
+ #expect(AppFolders(url: damaged).add([directory.url]) == .notSaved(.damaged), "a list it can't read was written over")
+ #expect(try String(contentsOf: damaged, encoding: .utf8) == "not a list")
+ }
+
+ @Test(.permissionsHold) func saysWhyAChangeCouldNotBeSaved() throws {
+ let directory = try TemporaryDirectory()
+ let folder = try directory.directory("Peel")
+ let tools = try directory.directory("Tools")
+ try directory.setPermissions(0o500, of: folder)
+ defer { try? directory.setPermissions(0o755, of: folder) }
+
+ let refusedWrite = SystemError(domain: NSCocoaErrorDomain, code: NSFileWriteNoPermissionError)
+ #expect(AppFolders(url: folder.appending(path: "app-folders.json")).add([tools]) == .notSaved(.failed(refusedWrite)))
}
@Test func startsNothingOverWhileTheListCanBeRead() throws {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
index 58fec78b..29828ce0 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
@@ -273,6 +273,7 @@ struct AppInspectorTests {
let scan = await AppCatalog.scan(choices: AppFolders(url: list))
#expect(scan.listOfFoldersUnreadable && !scan.readEverything)
+ #expect(scan.whyListOfFoldersUnreadable == .damaged)
#expect(!scan.unreadable.contains(list))
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
index a0495956..821add61 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
@@ -56,6 +56,8 @@ struct CommandLineTests {
#expect(Output.unreadableNote(for: leftOut)?.contains("no longer looks in /Volumes/Backup") == true)
let listUnread = AppScan(apps: [], unreadable: [], needsFullDiskAccess: false, chosenFolders: nil)
#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.")
+ let damaged = AppScan(apps: [], chosenFolders: nil, whyListOfFoldersUnreadable: .damaged)
+ #expect(Output.unreadableNote(for: damaged)?.hasSuffix("App Folders. The file's contents aren't in a form Peel can read.") == true)
}
/// 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/DeveloperCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
index 013ce64e..5e9895d8 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
@@ -549,7 +549,7 @@ struct DeveloperCachesTests {
try directory.file("Library/Application Support/Chat/Local State")
try directory.file("Library/Application Support/Chat/GPUCache/data_0", bytes: 4_096)
let chosen = directory.url.appending(path: "Library/Application Support/Peel/app-folders.json")
- try #require(AppFolders(url: chosen).add([tools]))
+ try #require(AppFolders(url: chosen).add([tools]) == .saved)
let environment = SearchEnvironment(homeDirectory: directory.url, rootDirectory: directory.url)
let environments = await DeveloperCaches.scan(in: environment)
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
index 83e7441f..fc938a09 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
@@ -773,6 +773,8 @@ struct FileCommandTests {
#expect(said?.hasPrefix("Peel couldn't read /Volumes/Old/f1x, /Volumes/Old/f2x, /Volumes/Old/f3x, /Volumes/Old/f4x, and 56 more folders, so") == true)
let list = AppScan(apps: [], unreadable: [], needsFullDiskAccess: false, chosenFolders: nil)
#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.")
+ let damaged = AppScan(apps: [], chosenFolders: nil, whyListOfFoldersUnreadable: .damaged)
+ #expect(OrphansCommand.refusal(for: damaged)?.description.hasSuffix("App Folders. The file's contents aren't in a form Peel can read.") == true)
}
/// 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/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
index ad461dd8..26c0d2ee 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
@@ -947,7 +947,8 @@ struct InstallersTests {
try directory.file("Apps/Install macOS Ventura.app/Contents/MacOS/app", bytes: 400_000)
try directory.file("Apps/Install Tool.app/Contents/MacOS/app", bytes: 400_000)
let chosen = home.appending(path: "Library/Application Support/Peel/app-folders.json")
- try #require(AppFolders(url: chosen).add([directory.url.appending(path: "Apps", directoryHint: .isDirectory)]))
+ let apps = directory.url.appending(path: "Apps", directoryHint: .isDirectory)
+ try #require(AppFolders(url: chosen).add([apps]) == .saved)
let scan = await Installers.scan(
installedApps: [], home: home, root: directory.url.appending(path: "root", directoryHint: .isDirectory),
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PeelFolderTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PeelFolderTests.swift
index b14ebeef..15bb4265 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/PeelFolderTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/PeelFolderTests.swift
@@ -24,7 +24,7 @@ struct PeelFolderTests {
PeelFolder.take(folder)
FileLock.whileHeld(beside: file("a.json")) {}
- #expect(!AppFolders(url: file("app-folders.json")).add([directory.url]))
+ #expect(AppFolders(url: file("app-folders.json")).add([directory.url]) != .saved)
#expect(!HomebrewChoice(url: file("homebrew.json")).save(nil))
#expect(!ShellFile.write(ShellFile.Choices(), to: file("Terminal/zshrc")))
#expect(!SSHFile.write([], to: file("Terminal/ssh_config")))
diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swift
index 0fc31785..056e61ac 100644
--- a/Peel/Model/AppLibrary.swift
+++ b/Peel/Model/AppLibrary.swift
@@ -75,6 +75,8 @@ final class AppLibrary {
/// Counts the changes the person makes to that list, so a reading that began before one never shows its older list.
@ObservationIgnored private var folderChanges = 0
private(set) var couldNotSaveFolders = false
+ /// Why the last change of that list couldn't be saved, when Peel knows.
+ private(set) var whyFoldersNotSaved: FileProblem?
/// What the last reading of the folders could not read, so the apps in it are missing from `apps`
/// (`AppScan.unreadable`).
private(set) var unreadable: [URL] = []
@@ -82,6 +84,7 @@ final class AppLibrary {
private(set) var unreadableNeedsFullDiskAccess = false
/// Whether the last reading could not read the list of chosen folders (`AppScan.listOfFoldersUnreadable`).
private(set) var listOfFoldersUnreadable = false
+ private(set) var whyListOfFoldersUnreadable: FileProblem?
/// Whether the last reading read every app, which Orphaned Files waits for.
var readEverything: Bool { listing.readEverything }
@@ -299,7 +302,10 @@ final class AppLibrary {
@discardableResult
func startFoldersOver() -> StartOver {
let answer = appFolders.startOver()
- if answer == .started { couldNotSaveFolders = false }
+ if answer == .started {
+ couldNotSaveFolders = false
+ whyFoldersNotSaved = nil
+ }
folderChanges += 1
folders = appFolders.load()
foldersLeftOut = appFolders.leftOut()
@@ -308,8 +314,15 @@ final class AppLibrary {
var foldersFile: URL { appFolders.url }
- private func changeFolders(_ change: (AppFolders) -> Bool) {
- couldNotSaveFolders = !change(appFolders)
+ private func changeFolders(_ change: (AppFolders) -> AppFolders.Change) {
+ switch change(appFolders) {
+ case .saved:
+ couldNotSaveFolders = false
+ whyFoldersNotSaved = nil
+ case .notSaved(let why):
+ couldNotSaveFolders = true
+ whyFoldersNotSaved = why
+ }
folderChanges += 1
folders = appFolders.load()
foldersLeftOut = appFolders.leftOut()
@@ -408,6 +421,9 @@ final class AppLibrary {
if listOfFoldersUnreadable != scan.listOfFoldersUnreadable {
listOfFoldersUnreadable = scan.listOfFoldersUnreadable
}
+ if whyListOfFoldersUnreadable != scan.whyListOfFoldersUnreadable {
+ whyListOfFoldersUnreadable = scan.whyListOfFoldersUnreadable
+ }
if unreadableNeedsFullDiskAccess != scan.needsFullDiskAccess {
unreadableNeedsFullDiskAccess = scan.needsFullDiskAccess
}
diff --git a/Peel/Views/AppList.swift b/Peel/Views/AppList.swift
index 693e59b0..2a125828 100644
--- a/Peel/Views/AppList.swift
+++ b/Peel/Views/AppList.swift
@@ -21,7 +21,7 @@ struct AppList: View {
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."),
+ detail: Text(verbatim: library.unreadableListOfFolders(saying: String(localized: "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
) {
StartOverButton(file: library.foldersFile, startedOver: "Started the list of app folders over.") {
diff --git a/Peel/Views/Intel/IntelList.swift b/Peel/Views/Intel/IntelList.swift
index a0b02f9a..46e853a7 100644
--- a/Peel/Views/Intel/IntelList.swift
+++ b/Peel/Views/Intel/IntelList.swift
@@ -157,7 +157,7 @@ struct IntelList: View {
let paths = unread.map(\.abbreviatedPath)
let jobFiles = closedJobFiles.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.")] : [])
+ ? [Text(verbatim: library.unreadableListOfFolders(saying: String(localized: "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.")])
+ why(closed.unread, of: paths.count)
diff --git a/Peel/Views/Orphans/OrphanList.swift b/Peel/Views/Orphans/OrphanList.swift
index d0fe9122..5edffdf1 100644
--- a/Peel/Views/Orphans/OrphanList.swift
+++ b/Peel/Views/Orphans/OrphanList.swift
@@ -38,7 +38,7 @@ struct OrphanList: View {
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 list = Text(verbatim: library.unreadableListOfFolders(saying: String(localized: "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 \(RemovalFailureAlert.listedFolders(library.unreadable.map(\.abbreviatedPath))), 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.")
let parts = (library.listOfFoldersUnreadable ? [list] : [])
+ (library.unreadable.isEmpty ? [] : [unread])
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index e67a73ed..78a5af0d 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -278,6 +278,18 @@ extension FileProblem? {
}
}
+extension AppLibrary {
+ /// `sentence`, then why Peel can't read its list of app folders, when Peel knows.
+ func unreadableListOfFolders(saying sentence: String) -> String {
+ whyListOfFoldersUnreadable.said(after: sentence, about: foldersFile)
+ }
+
+ /// That the folders couldn't be saved, then why, when Peel knows.
+ var foldersNotSaved: String {
+ whyFoldersNotSaved.said(after: String(localized: "Peel couldn’t save the app folders."), about: foldersFile)
+ }
+}
+
extension ExclusionsStore {
/// That nothing moves until the list starts over, then why it couldn't be read, when Peel knows.
var nothingMovesUntilStartedOver: String {
diff --git a/Peel/Views/Settings/AppFoldersSection.swift b/Peel/Views/Settings/AppFoldersSection.swift
index ee201f16..8e6acb7e 100644
--- a/Peel/Views/Settings/AppFoldersSection.swift
+++ b/Peel/Views/Settings/AppFoldersSection.swift
@@ -35,7 +35,7 @@ struct AppFoldersSection: View {
.foregroundStyle(.secondary)
} else {
HStack(spacing: 8) {
- StatusLabel(title: 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."))
+ StatusLabel(title: Text(verbatim: library.unreadableListOfFolders(saying: String(localized: "Peel can’t read its list of app folders, so Orphaned Files lists nothing. Starting over keeps the old list beside a new one."))))
Spacer(minLength: 8)
StartOverButton(file: library.foldersFile, startedOver: "Started the list of app folders over.") {
library.startFoldersOver()
@@ -56,7 +56,7 @@ struct AppFoldersSection: View {
}
}
if library.couldNotSaveFolders {
- StatusLabel(title: Text("Peel couldn’t save the app folders."))
+ StatusLabel(title: Text(verbatim: library.foldersNotSaved))
}
ListEditingButtons {
Button("Add Folder…", systemImage: "plus") {
diff --git a/PeelTests/AppLibraryTests.swift b/PeelTests/AppLibraryTests.swift
index 2a64b3a2..30c5e521 100644
--- a/PeelTests/AppLibraryTests.swift
+++ b/PeelTests/AppLibraryTests.swift
@@ -1130,11 +1130,16 @@ private nonisolated final class TestClock: Sendable {
try Data("not a list".utf8).write(to: list.url)
await library.refresh()
#expect(library.listOfFoldersUnreadable && library.folders == nil)
+ #expect(library.whyListOfFoldersUnreadable == .damaged)
+ library.addFolders([folder])
+ #expect(library.couldNotSaveFolders && library.whyFoldersNotSaved == .damaged)
#expect(library.startFoldersOver() == .started)
#expect(library.folders == [])
+ #expect(!library.couldNotSaveFolders && library.whyFoldersNotSaved == nil)
await library.refresh()
#expect(library.folders == [] && !library.listOfFoldersUnreadable)
+ #expect(library.whyListOfFoldersUnreadable == nil)
}
@Test func onlyTheReadingsThePersonAskedForAreToldToVoiceOver() async throws {