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 exclusions couldn't be read or saved

Țugui Dragoșbec38931e49a
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 573466f0..d6b8e8e2 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -205963,6 +205963,112 @@
}
}
},
+ "The file’s contents aren’t in a form Peel can read." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Obsah souboru není ve formátu, který by Peel dokázal přečíst."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Der Inhalt der Datei liegt nicht in einer Form vor, die Peel lesen kann."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "El contenido del archivo no está en un formato que Peel pueda leer."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Le contenu du fichier n’est pas dans un format que Peel peut lire."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Il contenuto del file non è in un formato che Peel possa leggere."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "このファイルの内容は、Peelが読み取れる形式ではありません。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "파일의 내용이 Peel이 읽을 수 있는 형식이 아닙니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "De inhoud van het bestand heeft geen indeling die Peel kan lezen."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zawartość pliku nie jest w formie, którą Peel może odczytać."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O conteúdo do arquivo não está em um formato que o Peel consiga ler."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Conținutul fișierului nu este într‑un format pe care Peel să îl poată citi."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Содержимое файла имеет формат, который Peel не может прочитать."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Filens innehåll är inte i ett format som Peel kan läsa."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dosyanın içeriği Peel’in okuyabileceği bir biçimde değil."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Вміст файлу має формат, якого Peel не може прочитати."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "该文件的内容不是Peel可以读取的格式。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "此檔案的內容不是Peel能讀取的格式。"
+ }
+ }
+ }
+ },
"The filters you chose may leave out what you’re looking for." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/ExclusionCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/ExclusionCommands.swift
index c4b85b1d..d0ffb5b3 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/ExclusionCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/ExclusionCommands.swift
@@ -15,7 +15,7 @@ struct ExclusionsCommand: AsyncParsableCommand {
/// file aside and silently drop what the user chose. Only the app starts a new list, after warning the user.
static func current(in store: ExclusionStore, whenUnreadable said: String = unreadable) async throws -> Exclusions {
let exclusions = await store.load()
- guard !exclusions.isUnreadable else { throw CommandFailure(said) }
+ guard !exclusions.isUnreadable else { throw CommandFailure(said + exclusions.whyUnreadable.sentence) }
return exclusions
}
@@ -33,10 +33,10 @@ struct ExclusionsCommand: AsyncParsableCommand {
switch await store.change(transform) {
case .saved:
return
- case .unreadable:
- throw CommandFailure(unreadable)
- case .notSaved:
- throw CommandFailure("Peel couldn't write its exclusions, so nothing changed.")
+ case .unreadable(let why):
+ throw CommandFailure(unreadable + why.sentence)
+ case .notSaved(_, let why):
+ throw CommandFailure("Peel couldn't write its exclusions, so nothing changed." + why.sentence)
}
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
index 6310b1a0..6ca56b33 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
@@ -821,7 +821,7 @@ struct DuplicatesCommand: AsyncParsableCommand {
/// Comparing reads files, so nothing is compared while the exclusions can't be read.
static func refusal(for exclusions: Exclusions, savedAt url: URL) -> CommandFailure? {
guard exclusions.isUnreadable else { return nil }
- return CommandFailure("Peel couldn't read your exclusions at \(Output.plain(url.path(percentEncoded: false))), so it compares nothing, since it would read what you asked it to leave alone. Open Peel and click Start Over in Settings > Exclusions.")
+ return CommandFailure("Peel couldn't read your exclusions at \(Output.plain(url.path(percentEncoded: false))), so it compares nothing, since it would read what you asked it to leave alone. Open Peel and click Start Over in Settings > Exclusions." + exclusions.whyUnreadable.sentence)
}
func run() async throws {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
index 403cb030..d30bd5ed 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
@@ -368,7 +368,9 @@ struct RestoreCommand: AsyncParsableCommand {
func run(in log: RemovalLog, using service: TrashService) async throws {
guard service.knowsTheExclusions else {
- throw AppLookup.Failure.exclusionsUnreadable(ExclusionStore.defaultURL.path(percentEncoded: false))
+ throw AppLookup.Failure.exclusionsUnreadable(
+ ExclusionStore.defaultURL.path(percentEncoded: false), service.whyExclusionsAreUnreadable
+ )
}
let outcome = await log.load()
guard let records = outcome.records else {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift
index 088d5363..030407bb 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift
@@ -7,7 +7,7 @@ enum AppLookup {
case ambiguous(String, [String])
case notAnApp(String)
case excluded(String)
- case exclusionsUnreadable(String)
+ case exclusionsUnreadable(String, FileProblem?)
var description: String {
switch self {
@@ -19,8 +19,8 @@ enum AppLookup {
"\(Output.plain(path)) isn't an app."
case .excluded(let name):
"\(Output.plain(name)) is excluded in Peel's settings, so Peel leaves it alone."
- case .exclusionsUnreadable(let path):
- "Peel couldn't read your exclusions at \(Output.plain(path)), so it left everything alone. Open Peel and click Start Over in Settings > Exclusions."
+ case .exclusionsUnreadable(let path, let why):
+ "Peel couldn't read your exclusions at \(Output.plain(path)), so it left everything alone. Open Peel and click Start Over in Settings > Exclusions." + why.sentence
}
}
}
@@ -40,7 +40,9 @@ enum AppLookup {
by exclusions: Exclusions,
savedAt url: URL = ExclusionStore.defaultURL
) -> Failure? {
- guard !exclusions.isUnreadable else { return .exclusionsUnreadable(url.path(percentEncoded: false)) }
+ guard !exclusions.isUnreadable else {
+ return .exclusionsUnreadable(url.path(percentEncoded: false), exclusions.whyUnreadable)
+ }
return exclusions.excludes(app) ? .excluded(app.name) : nil
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift
index 48671432..4be2eb4a 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift
@@ -87,7 +87,9 @@ struct Cleanup {
}
// The guard then refuses everything, which says nothing of the items, so no refusal is recorded.
guard service.knowsTheExclusions else {
- throw AppLookup.Failure.exclusionsUnreadable(ExclusionStore.defaultURL.path(percentEncoded: false))
+ throw AppLookup.Failure.exclusionsUnreadable(
+ ExclusionStore.defaultURL.path(percentEncoded: false), service.whyExclusionsAreUnreadable
+ )
}
// Refused items never reach the move, so their failures are built here and recorded, just as the app
// records the refusals its service reports.
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index 2b0316b8..dc62f36e 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -301,6 +301,7 @@ extension FileProblem? {
switch self {
case .notAFile: " Something other than a file, such as a folder, is where the file should be."
case .tooLarge: " The file is larger than Peel ever writes it, so Peel doesn't read it."
+ case .damaged: " The file's contents aren't in a form Peel can read."
case .failed(let error): " macOS answered: \(Output.plain(error.localizedDescription))"
case nil: ""
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableExclusions.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableExclusions.swift
index b20a2258..27ed7c16 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableExclusions.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableExclusions.swift
@@ -10,9 +10,10 @@ enum UnreadableExclusions {
) -> String? {
guard exclusions.isUnreadable else { return nil }
let place = Output.plain(url.path(percentEncoded: false))
- return listsEverything
+ let said = listsEverything
? "Peel couldn't read your exclusions at \(place), so this may list what you asked it to leave alone, and nothing will be moved. Open Peel and click Start Over in Settings > Exclusions."
: "Peel couldn't read your exclusions at \(place). Open Peel and click Start Over in Settings > Exclusions."
+ return said + exclusions.whyUnreadable.sentence
}
static func load(from store: ExclusionStore = ExclusionStore(), listsEverything: Bool = true) async -> Exclusions {
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift
index c0c5d040..1907edb0 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift
@@ -82,6 +82,7 @@ struct RemovalGuard: Sendable {
private let syncKeeper: @Sendable (URL) -> SyncKeeper?
var knowsTheExclusions: Bool { exclusions.isKnown }
+ var whyExclusionsAreUnreadable: FileProblem? { exclusions.whyUnreadable }
func excludes(_ app: InstalledApp) -> Bool { exclusions.excludes(app) }
func excludes(ownerOf item: BackgroundItem) -> Bool { item.isOfAnApp(excludedBy: exclusions) }
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
index 03eda764..c85c81de 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
@@ -427,6 +427,7 @@ public struct TrashService: Sendable {
/// False while the saved exclusions are not read yet or cannot be read, when nothing moves.
public var knowsTheExclusions: Bool { removalGuard.knowsTheExclusions }
+ public var whyExclusionsAreUnreadable: FileProblem? { removalGuard.whyExclusionsAreUnreadable }
func excludes(_ app: InstalledApp) -> Bool { removalGuard.excludes(app) }
func excludes(ownerOf item: BackgroundItem) -> Bool { removalGuard.excludes(ownerOf: item) }
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift b/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
index 3e776b3b..b4d54af2 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
@@ -19,6 +19,8 @@ public struct Exclusions: Sendable, Codable, Hashable {
/// True when the saved list exists but could not be read, so what the user excluded is unknown. Nothing is
/// moved while this is true.
public private(set) var isUnreadable = false
+ /// Why the saved list could not be read, when Peel knows.
+ public private(set) var whyUnreadable: FileProblem?
/// False until the saved list has been read. Nothing is moved before, as for a list that cannot be read.
public private(set) var hasBeenRead = true
@@ -26,11 +28,14 @@ public struct Exclusions: Sendable, Codable, Hashable {
public var isKnown: Bool { hasBeenRead && !isUnreadable }
public static let none = Exclusions()
- public static let unreadable: Exclusions = {
+ public static let unreadable = Exclusions.unreadable(because: nil)
+
+ public static func unreadable(because why: FileProblem?) -> Exclusions {
var exclusions = Exclusions()
exclusions.isUnreadable = true
+ exclusions.whyUnreadable = why
return exclusions
- }()
+ }
/// The list before the saved one has been read.
public static let notYetRead: Exclusions = {
var exclusions = Exclusions()
@@ -46,7 +51,7 @@ public struct Exclusions: Sendable, Codable, Hashable {
/// Compares what is excluded. `spellings` and `appFolderNames` are left out, since they are worked out.
public static func == (one: Exclusions, other: Exclusions) -> Bool {
one.paths == other.paths && one.bundleIdentifiers == other.bundleIdentifiers
- && one.isUnreadable == other.isUnreadable
+ && one.isUnreadable == other.isUnreadable && one.whyUnreadable == other.whyUnreadable
&& one.hasBeenRead == other.hasBeenRead
}
@@ -54,6 +59,7 @@ public struct Exclusions: Sendable, Codable, Hashable {
hasher.combine(paths)
hasher.combine(bundleIdentifiers)
hasher.combine(isUnreadable)
+ hasher.combine(whyUnreadable)
hasher.combine(hasBeenRead)
}
@@ -356,11 +362,11 @@ public struct ExclusionStore: Sendable {
public enum Outcome: Sendable, Equatable {
/// The list as it was saved.
case saved(Exclusions)
- /// The saved list cannot be read, so it was left as it is.
- case unreadable
+ /// The saved list cannot be read, so it was left as it is; and why, when Peel knows.
+ case unreadable(FileProblem?)
/// The list could not be written. It carries what the list would have been, which the app keeps until it
- /// quits.
- case notSaved(Exclusions)
+ /// quits, and why, when Peel knows.
+ case notSaved(Exclusions, FileProblem?)
}
/// Loads the saved list. No file means an empty list. A file that cannot be read or reached gives `.unreadable`,
@@ -391,28 +397,33 @@ public struct ExclusionStore: Sendable {
FileLock.whileHeld(beside: url) {
var exclusions = read()
if exclusions.isUnreadable {
- guard startsOver else { return .unreadable }
+ guard startsOver else { return .unreadable(exclusions.whyUnreadable) }
exclusions = .none
}
transform(&exclusions)
- return write(exclusions) ? .saved(exclusions) : .notSaved(exclusions)
+ return save(exclusions)
}
}
private func read() -> Exclusions {
guard !url.isMissing else { return .none }
- guard let data = BoundedRead.data(at: url), let saved = try? JSONDecoder().decode(Exclusions.self, from: data)
- else {
- return .unreadable
+ guard let data = BoundedRead.data(at: url) else { return .unreadable(because: BoundedRead.whyUnreadable(url)) }
+ guard let saved = try? JSONDecoder().decode(Exclusions.self, from: data) else {
+ return .unreadable(because: .damaged)
}
return saved
}
- private func write(_ exclusions: Exclusions) -> Bool {
+ private func save(_ exclusions: Exclusions) -> Outcome {
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
- guard let data = try? encoder.encode(exclusions) else { return false }
- if read().isUnreadable, DamagedFile.setAside(url) == nil { return false }
- return (try? PeelFolder.write(data, to: url)) != nil
+ do {
+ let data = try encoder.encode(exclusions)
+ if read().isUnreadable, DamagedFile.setAside(url) == nil { return .notSaved(exclusions, nil) }
+ try PeelFolder.write(data, to: url)
+ return .saved(exclusions)
+ } catch {
+ return .notSaved(exclusions, .failed(SystemError(error)))
+ }
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/FileProblem.swift b/Packages/PeelCore/Sources/PeelCore/Support/FileProblem.swift
index cc507b50..581662e8 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/FileProblem.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/FileProblem.swift
@@ -3,5 +3,7 @@ public enum FileProblem: Error, Sendable, Hashable {
case notAFile
/// It is larger than Peel reads a file of its kind.
case tooLarge
+ /// What it holds isn't in the form Peel writes, as after an edit by hand.
+ case damaged
case failed(SystemError)
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
index 41771a9f..a0495956 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
@@ -355,7 +355,7 @@ struct CommandLineTests {
try AppLookup.refuseIfExcluded(editor, by: exclusions)
}
}
- #expect(throws: AppLookup.Failure.exclusionsUnreadable("/tmp/exclusions.json")) {
+ #expect(throws: AppLookup.Failure.exclusionsUnreadable("/tmp/exclusions.json", nil)) {
try AppLookup.refuseIfExcluded(editor, by: .unreadable, savedAt: URL(filePath: "/tmp/exclusions.json"))
}
}
@@ -367,6 +367,8 @@ struct CommandLineTests {
#expect(UnreadableExclusions.note(for: Exclusions(bundleIdentifiers: ["com.example.editor"])) == nil)
let note = try #require(UnreadableExclusions.note(for: .unreadable, savedAt: URL(filePath: "/tmp/exclusions.json")))
#expect(note.contains("/tmp/exclusions.json"))
+ let damaged = UnreadableExclusions.note(for: .unreadable(because: .damaged))
+ #expect(damaged?.hasSuffix("Settings > Exclusions. The file's contents aren't in a form Peel can read.") == true)
}
@Test func aSearchDoesNotSayItListsWhatItLeavesOut() throws {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionCommandTests.swift
index 1e3a66c5..e07dc979 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionCommandTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionCommandTests.swift
@@ -244,7 +244,7 @@ struct ExclusionCommandTests {
let store = store(in: directory)
try directory.file("Peel/exclusions.json", contents: Data("not json".utf8))
- await #expect(throws: CommandFailure.self) {
+ let added = await #expect(throws: CommandFailure.self) {
try await add(["/Users/me/thing"], in: store)
}
await #expect(throws: CommandFailure.self) {
@@ -253,8 +253,10 @@ struct ExclusionCommandTests {
let failure = await #expect(throws: CommandFailure.self) {
try await list(in: store)
}
+ #expect(added?.description.hasSuffix(" The file's contents aren't in a form Peel can read.") == true)
#expect(failure?.description.contains("won't change it") == false, "nobody asked for a change")
#expect(failure?.description.contains("Start Over") == true)
+ #expect(failure?.description.hasSuffix(" The file's contents aren't in a form Peel can read.") == true)
#expect(try Data(contentsOf: store.url) == Data("not json".utf8))
}
@@ -270,9 +272,10 @@ struct ExclusionCommandTests {
)
}
- await #expect(throws: CommandFailure.self) {
+ let failure = await #expect(throws: CommandFailure.self) {
try await add(["/Users/me/thing"], in: store)
}
+ #expect(failure?.description.contains("nothing changed. macOS answered: ") == true)
}
/// The listing has one row per item, paths before apps, each path written in full without a trailing slash.
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift
index b232a6da..3ed3fee6 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift
@@ -388,7 +388,7 @@ struct ExclusionsTests {
let outcome = await ExclusionStore(url: file).change { $0.bundleIdentifiers.insert("com.example.app") }
- #expect(outcome == .unreadable)
+ #expect(outcome == .unreadable(.damaged))
#expect(try String(contentsOf: file, encoding: .utf8) == "not json")
}
@@ -426,7 +426,9 @@ struct ExclusionsTests {
let outcome = await store.change { $0.paths.insert(URL(filePath: "/Users/x/Added")) }
- #expect(outcome == .notSaved(Exclusions(paths: [URL(filePath: "/Users/x/Kept"), URL(filePath: "/Users/x/Added")])))
+ let refusedWrite = SystemError(domain: NSCocoaErrorDomain, code: NSFileWriteNoPermissionError)
+ let wouldHaveSaved = Exclusions(paths: [URL(filePath: "/Users/x/Kept"), URL(filePath: "/Users/x/Added")])
+ #expect(outcome == .notSaved(wouldHaveSaved, .failed(refusedWrite)))
#expect(await store.load().paths == [URL(filePath: "/Users/x/Kept")])
}
@@ -447,11 +449,14 @@ struct ExclusionsTests {
let directory = try TemporaryDirectory()
let broken = try directory.file("broken.json", contents: Data(#"{"paths":["file:///Users/x/Vault/""#.utf8))
let locked = try directory.file("locked.json", contents: Data(#"{"paths":[]}"#.utf8))
+ let folder = try directory.directory("folder.json")
try directory.setPermissions(0, of: "locked.json")
defer { try? directory.setPermissions(0o644, of: "locked.json") }
- #expect(await ExclusionStore(url: broken).load().isUnreadable)
- #expect(await ExclusionStore(url: locked).load().isUnreadable)
+ let closed = SystemError(domain: NSPOSIXErrorDomain, code: Int(EACCES))
+ #expect(await ExclusionStore(url: broken).load() == .unreadable(because: .damaged))
+ #expect(await ExclusionStore(url: locked).load() == .unreadable(because: .failed(closed)))
+ #expect(await ExclusionStore(url: folder).load() == .unreadable(because: .notAFile))
#expect(await ExclusionStore(url: directory.url.appending(path: "missing.json")).load() == .none)
}
@@ -480,8 +485,10 @@ struct ExclusionsTests {
try directory.setPermissions(0o600, of: "Peel")
defer { try? directory.setPermissions(0o755, of: "Peel") }
- #expect(await ExclusionStore(url: file).load().isUnreadable)
- #expect(await ExclusionStore(url: link).load().isUnreadable)
+ let closed = SystemError(domain: NSPOSIXErrorDomain, code: Int(EACCES))
+ let nothingThere = SystemError(domain: NSPOSIXErrorDomain, code: Int(ENOENT))
+ #expect(await ExclusionStore(url: file).load() == .unreadable(because: .failed(closed)))
+ #expect(await ExclusionStore(url: link).load() == .unreadable(because: .failed(nothingThere)))
}
/// Until the app has read the saved list, what the user excluded is not known, so nothing moves, as for a list
diff --git a/Peel/Model/ExclusionsStore.swift b/Peel/Model/ExclusionsStore.swift
index f05e91f5..faedb5a3 100644
--- a/Peel/Model/ExclusionsStore.swift
+++ b/Peel/Model/ExclusionsStore.swift
@@ -14,6 +14,8 @@ final class ExclusionsStore {
private(set) var revision = 0
/// The last change could not be written, so it will not be there after a relaunch.
private(set) var couldNotSave = false
+ /// Why the last change could not be written, when Peel knows.
+ private(set) var whyNotSaved: FileProblem?
/// The changes that could not be written. They stay in force until Peel quits, as Settings says, laid again
/// over the list each time it is read, and the next change that is written takes them with it.
@ObservationIgnored private var unsaved: [@Sendable (inout Exclusions) -> Void] = []
@@ -27,6 +29,8 @@ final class ExclusionsStore {
self.store = store
}
+ var file: URL { store.url }
+
func needsRescan(_ page: String) -> Bool {
scanned.needsRescan(page, at: revision)
}
@@ -66,6 +70,7 @@ final class ExclusionsStore {
if answer == .started {
unsaved = []
couldNotSave = false
+ whyNotSaved = nil
}
show(withUnsaved(await store.load()))
return answer
@@ -81,13 +86,15 @@ final class ExclusionsStore {
case .saved(let saved):
unsaved = []
couldNotSave = false
+ whyNotSaved = nil
show(saved)
- case .notSaved(let changed):
+ case .notSaved(let changed, let why):
unsaved.append(transform)
couldNotSave = true
+ whyNotSaved = why
show(changed)
- case .unreadable:
- show(.unreadable)
+ case .unreadable(let why):
+ show(.unreadable(because: why))
}
}
}
diff --git a/Peel/Views/Home/HomePermissionsView.swift b/Peel/Views/Home/HomePermissionsView.swift
index eb40a0dc..316bf67e 100644
--- a/Peel/Views/Home/HomePermissionsView.swift
+++ b/Peel/Views/Home/HomePermissionsView.swift
@@ -228,7 +228,7 @@ struct HomePermissionsContent: View {
if held == .exclusionsUnreadable {
Notice(
title: Text("Peel couldn’t read your exclusions"),
- detail: Text("Peel removes nothing and puts nothing back until you start the list over in Settings."),
+ detail: Text(verbatim: exclusions.nothingMovesUntilStartedOver),
isAlbum: true
) {
Button("Open Peel Settings") { SettingsPane.exclusions.open(with: openSettings) }
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index d645bdda..e67a73ed 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -264,6 +264,7 @@ extension FileProblem {
let why = switch self {
case .notAFile: String(localized: "Something other than a file, such as a folder, is where the file should be.")
case .tooLarge: String(localized: "The file is larger than Peel ever writes it, so Peel doesn’t read it.")
+ case .damaged: String(localized: "The file’s contents aren’t in a form Peel can read.")
case .failed(let error): String(localized: "macOS answered: \(error.description(of: url))")
}
return [sentence, why].joined(separator: " ")
@@ -277,6 +278,13 @@ extension FileProblem? {
}
}
+extension ExclusionsStore {
+ /// That nothing moves until the list starts over, then why it couldn't be read, when Peel knows.
+ var nothingMovesUntilStartedOver: String {
+ exclusions.whyUnreadable.said(after: String(localized: "Peel removes nothing and puts nothing back until you start the list over in Settings."), about: file)
+ }
+}
+
extension HistoryWriteProblem {
/// What keeps History from being written, and that nothing moves meanwhile, read from `bundle`, or from the main
/// bundle when it is nil.
diff --git a/Peel/Views/RemovalsHeldBanner.swift b/Peel/Views/RemovalsHeldBanner.swift
index 3f46aad0..485eabb8 100644
--- a/Peel/Views/RemovalsHeldBanner.swift
+++ b/Peel/Views/RemovalsHeldBanner.swift
@@ -45,7 +45,7 @@ struct RemovalsHeldBanner: View {
if held == .exclusionsUnreadable {
Notice(
title: Text("Peel couldn’t read your exclusions"),
- detail: Text("Peel removes nothing and puts nothing back until you start the list over in Settings.")
+ detail: Text(verbatim: exclusions.nothingMovesUntilStartedOver)
) {
Button("Open Peel Settings") { SettingsPane.exclusions.open(with: openSettings) }
}
diff --git a/Peel/Views/ResetSheet.swift b/Peel/Views/ResetSheet.swift
index e43864bf..7d37fe1b 100644
--- a/Peel/Views/ResetSheet.swift
+++ b/Peel/Views/ResetSheet.swift
@@ -404,7 +404,7 @@ struct ResetSheet: View {
case .exclusionsNotKnown:
VStack(alignment: .leading, spacing: 2) {
StatusLabel(title: Text("Peel couldn’t read your exclusions"), tint: .red)
- Text("Peel removes nothing and puts nothing back until you start the list over in Settings.")
+ Text(verbatim: exclusions.nothingMovesUntilStartedOver)
}
.font(.callout)
.foregroundStyle(.secondary)
diff --git a/Peel/Views/Settings/ExclusionsSettingsView.swift b/Peel/Views/Settings/ExclusionsSettingsView.swift
index 440877f7..3735a378 100644
--- a/Peel/Views/Settings/ExclusionsSettingsView.swift
+++ b/Peel/Views/Settings/ExclusionsSettingsView.swift
@@ -35,6 +35,14 @@ struct ExclusionsSettingsView: View {
}
}
+ private var unreadableDetail: String {
+ exclusions.exclusions.whyUnreadable.said(after: String(localized: "Until it can read them, or you start over, Peel removes nothing and puts nothing back, because it can’t tell what you asked it to leave alone. Adding or removing an entry below starts over too: the old file is kept beside the new one, but nothing in it counts anymore."), about: exclusions.file)
+ }
+
+ private var notSavedDetail: String {
+ exclusions.whyNotSaved.said(after: String(localized: "Your latest changes work in Peel until it quits. When it opens again, and in the peel command, the list is as it was last saved."), about: exclusions.file)
+ }
+
private var isShowingRefusal: Binding<Bool> {
Binding(get: { !refused.isEmpty }, set: { if !$0 { refused = [] } })
}
@@ -44,7 +52,7 @@ struct ExclusionsSettingsView: View {
if exclusions.exclusions.isUnreadable {
Notice(
title: Text("Peel couldn’t read your exclusions"),
- detail: Text("Until it can read them, or you start over, Peel removes nothing and puts nothing back, because it can’t tell what you asked it to leave alone. Adding or removing an entry below starts over too: the old file is kept beside the new one, but nothing in it counts anymore.")
+ detail: Text(verbatim: unreadableDetail)
) {
StartOverButton(file: ExclusionStore.defaultURL, startedOver: "Started the list of exclusions over.") {
await exclusions.startOver()
@@ -54,7 +62,7 @@ struct ExclusionsSettingsView: View {
if exclusions.couldNotSave {
Notice(
title: Text("Your exclusions couldn’t be saved"),
- detail: Text("Your latest changes work in Peel until it quits. When it opens again, and in the peel command, the list is as it was last saved.")
+ detail: Text(verbatim: notSavedDetail)
) {}
}
Section {
diff --git a/Peel/Views/Settings/SavedSettingsSection.swift b/Peel/Views/Settings/SavedSettingsSection.swift
index 5bcf1b19..3c50a21e 100644
--- a/Peel/Views/Settings/SavedSettingsSection.swift
+++ b/Peel/Views/Settings/SavedSettingsSection.swift
@@ -168,7 +168,7 @@ struct SavedSettingsSection: View {
case .exclusionsNotKnown:
failure = Failure(
title: String(localized: "Peel couldn’t read your exclusions"),
- message: String(localized: "Peel removes nothing and puts nothing back until you start the list over in Settings.")
+ message: exclusions.nothingMovesUntilStartedOver
)
case .excluded:
failure = Failure(
diff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swift
index 6d835313..4c6f304f 100644
--- a/Peel/Views/Settings/SettingsView.swift
+++ b/Peel/Views/Settings/SettingsView.swift
@@ -446,7 +446,7 @@ private struct GeneralSettingsView: View {
.foregroundStyle(.secondary)
}
} else if exclusions.exclusions.isUnreadable {
- Text("Peel removes nothing and puts nothing back until you start the list over in Settings.")
+ Text(verbatim: exclusions.nothingMovesUntilStartedOver)
.font(.callout)
.foregroundStyle(.secondary)
} else if let why = history.readProblem {
diff --git a/PeelTests/ExclusionsStoreTests.swift b/PeelTests/ExclusionsStoreTests.swift
index 286f96cd..251488db 100644
--- a/PeelTests/ExclusionsStoreTests.swift
+++ b/PeelTests/ExclusionsStoreTests.swift
@@ -16,12 +16,14 @@ struct ExclusionsStoreTests {
await exclusions.add(paths: [URL(filePath: "/Users/x/Kept")])
try FileManager.default.setAttributes([.posixPermissions: 0o500], ofItemAtPath: path)
await exclusions.add(paths: [URL(filePath: "/Users/x/Unsaved")])
- #expect(exclusions.couldNotSave)
+ let refusedWrite = SystemError(domain: NSCocoaErrorDomain, code: NSFileWriteNoPermissionError)
+ #expect(exclusions.couldNotSave && exclusions.whyNotSaved == .failed(refusedWrite))
let answer = await exclusions.startOver()
#expect(answer == .notNeeded)
#expect(exclusions.couldNotSave, "a change still unsaved was no longer said")
+ #expect(exclusions.whyNotSaved == .failed(refusedWrite))
#expect(exclusions.exclusions.paths.count == 2)
}
}