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 History or the Not Moved list couldn't be read or saved

Țugui Dragoș9bea5d0cbe3f
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 17ff3147..573466f0 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -190469,6 +190469,112 @@
}
}
},
+ "Something other than a file, such as a folder, is where the file should be." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tam, kde má být soubor, je něco jiného než soubor, například složka."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "An der Stelle der Datei liegt etwas anderes als eine Datei, etwa ein Ordner."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Donde debería estar el archivo hay algo que no es un archivo, como una carpeta."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Autre chose qu’un fichier, un dossier par exemple, se trouve là où devrait être le fichier."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dove dovrebbe trovarsi il file c’è qualcos’altro, come una cartella."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "ファイルがあるべき場所に、フォルダなど、ファイル以外のものがあります。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "파일이 있어야 할 위치에 폴더 등 파일이 아닌 항목이 있습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Op de plek van het bestand staat iets anders dan een bestand, zoals een map."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "W miejscu, w którym powinien być plik, jest coś innego, na przykład folder."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Há algo que não é um arquivo, como uma pasta, onde o arquivo deveria estar."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "În locul în care ar trebui să fie fișierul se află altceva, cum ar fi un dosar."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Там, где должен быть файл, находится что-то другое, например папка."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Något annat än en fil, till exempel en mapp, finns där filen ska ligga."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dosyanın olması gereken yerde dosya olmayan bir şey, örneğin bir klasör var."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Там, де має бути файл, лежить щось інше, наприклад папка."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "该文件应在的位置上是其他项目(例如文件夹),而不是文件。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "檔案應在的位置上是檔案夾之類的其他項目,而不是檔案。"
+ }
+ }
+ }
+ },
"Sort By" : {
"localizations" : {
"cs" : {
@@ -205751,6 +205857,112 @@
}
}
},
+ "The file is larger than Peel ever writes it, so Peel doesn’t read it." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Soubor je větší, než jaký by Peel kdy zapsal, takže ho Peel nečte."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Die Datei ist größer, als Peel sie je schreibt, daher liest Peel sie nicht."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "El archivo ocupa más de lo que Peel escribe nunca en él, así que Peel no lo lee."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Le fichier est plus volumineux que Peel ne l’écrit jamais : Peel ne le lit donc pas."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Il file è più grande di qualsiasi file che Peel scriva, quindi Peel non lo legge."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "このファイルは、Peelが書き込むことのあるサイズを超えているため、Peelは読み取りません。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel은 이 파일을 이렇게 크게 쓰는 일이 없으므로 이 파일을 읽지 않습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Het bestand is groter dan Peel het ooit schrijft, dus Peel leest het niet."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Plik jest większy niż jakikolwiek zapisywany przez Peel, więc Peel go nie odczytuje."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O arquivo é maior do que o Peel jamais o gravaria, então o Peel não o lê."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Fișierul este mai mare decât ar putea fi unul scris de Peel, așa că Peel nu îl citește."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel никогда не записывает этот файл таким большим, поэтому не читает его."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Filen är större än den någonsin blir när Peel skriver den, så Peel läser den inte."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dosya, Peel’in hiçbir zaman yazmayacağı kadar büyük, bu yüzden Peel onu okumaz."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Файл завеликий: Peel ніколи не записує його такого розміру, тож Peel його не читає."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "该文件比Peel写入的任何此类文件都大,因此Peel不会读取它。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "此檔案大於Peel會寫入的任何大小,因此Peel不會讀取它。"
+ }
+ }
+ }
+ },
"The filters you chose may leave out what you’re looking for." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
index 48391313..403cb030 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
@@ -287,7 +287,7 @@ struct HistoryCommand: AsyncParsableCommand {
return
}
let read = await log.load()
- guard let records = read.records else { throw CommandFailure((read.problem ?? .unreadable).summary) }
+ guard let records = read.records else { throw CommandFailure((read.problem ?? .unreadable(nil)).summary) }
if let problem = read.problem {
Output.note(problem.summary)
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index 54638802..2b0316b8 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -287,9 +287,22 @@ extension RemovalLogProblem {
var summary: String {
switch self {
case .damaged(let setAside): "History was damaged, so it was kept as \(Output.plain(Output.path(setAside))) and started again."
- case .unreadable: "History couldn't be read, so Peel moves nothing until you start it over in the Peel app's History."
- case .couldNotRecord: "History couldn't be saved, so the last removal isn't in it."
- case .couldNotUpdate: "History couldn't be saved, so what was put back is still listed in it."
+ case .unreadable(let why):
+ "History couldn't be read, so Peel moves nothing until you start it over in the Peel app's History." + why.sentence
+ case .couldNotRecord(let why): "History couldn't be saved, so the last removal isn't in it." + why.sentence
+ case .couldNotUpdate(let why): "History couldn't be saved, so what was put back is still listed in it." + why.sentence
+ }
+ }
+}
+
+extension FileProblem? {
+ /// Why, as a sentence of its own after the one it explains, or nothing when it isn't known.
+ var sentence: String {
+ 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 .failed(let error): " macOS answered: \(Output.plain(error.localizedDescription))"
+ case nil: ""
}
}
}
@@ -300,10 +313,11 @@ extension RefusalLogProblem {
case .damaged(let setAside):
"The list of refusals was damaged, so it was kept as \(Output.plain(Output.path(setAside)))"
+ " and started again."
- case .unreadable:
+ case .unreadable(let why):
"The list of refusals couldn't be read, so Peel writes nothing to it until you clear it with"
- + " `peel history --refused --clear` or start it over in the Peel app's History."
- case .couldNotRecord: "The list of refusals couldn't be saved, so what stayed this time isn't in it."
+ + " `peel history --refused --clear` or start it over in the Peel app's History." + why.sentence
+ case .couldNotRecord(let why):
+ "The list of refusals couldn't be saved, so what stayed this time isn't in it." + why.sentence
}
}
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableHistory.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableHistory.swift
index 1050b64a..ed61dc73 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableHistory.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableHistory.swift
@@ -5,7 +5,7 @@ import PeelCore
/// listed for Put Back, and the Peel app can start History over.
enum UnreadableHistory {
static func note(at url: URL = RemovalHistory.defaultURL) -> String? {
- guard !RemovalLog.canBeRead(at: url) else { return nil }
- return "Peel couldn't read its History at \(Output.plain(url.path(percentEncoded: false))), so nothing will be moved. Open Peel and click Start Over in History."
+ guard let problem = RemovalLog.readProblem(at: url) else { return nil }
+ return "Peel couldn't read its History at \(Output.plain(url.path(percentEncoded: false))), so nothing will be moved. Open Peel and click Start Over in History." + Optional(problem).sentence
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/LaunchAgentFile.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/LaunchAgentFile.swift
index 0db3e859..d63869ac 100644
--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/LaunchAgentFile.swift
+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/LaunchAgentFile.swift
@@ -86,7 +86,10 @@ public struct LaunchAgentFile: Sendable {
guard info.st_uid == owner else { return .failure(.notYours) }
guard info.st_size <= maximumBytes else { return .failure(.tooLarge) }
guard let (data, identity) = BoundedRead.contents(at: url, maximum: maximumBytes) else {
- return .failure(.unreadable(BoundedRead.openError(of: url)))
+ guard case .failed(let error)? = BoundedRead.whyUnreadable(url, maximum: maximumBytes) else {
+ return .failure(.unreadable(nil))
+ }
+ return .failure(.unreadable(error))
}
guard identity.holdsTheSameContents(as: FileIdentity(info)) else { return .failure(.changed) }
var format = PropertyListSerialization.PropertyListFormat.xml
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift
index 45a3a4c0..ba92e357 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift
@@ -52,10 +52,10 @@ public enum RefusalLogProblem: Sendable, Equatable {
/// The file could not be decoded. It was set aside under this name, and the rows that could be read were kept.
case damaged(setAside: URL)
/// The file could not be read or set aside, so nothing is written to it: it is the only copy of what was
- /// refused.
- case unreadable
+ /// refused. And why, when Peel knows.
+ case unreadable(FileProblem?)
/// What the last removal refused could not be written down.
- case couldNotRecord
+ case couldNotRecord(FileProblem?)
}
/// A record of what Peel was asked to move and refused, so the decisions can be read back. Only refusals of
@@ -107,8 +107,8 @@ public actor RefusalLog {
let trimmed = Batches.trimmed(
every, maximum: Self.maximumRecords, batch: { $0.batch ?? $0.id }, date: \.date, keeping: [batch]
)
- guard write(trimmed, keeping: [batch]) else {
- note(.couldNotRecord)
+ if let failure = write(trimmed, keeping: [batch]) {
+ note(.couldNotRecord(failure))
return problem
}
let listed = Set((kept?.records ?? trimmed).map { $0.batch ?? $0.id })
@@ -116,7 +116,7 @@ public actor RefusalLog {
if leftOut > 0 {
RemovalTotals.change(at: RemovalTotals.url(beside: url)) { $0.countRefusalsNoLongerListed(leftOut) }
}
- if problem == .couldNotRecord { problem = nil }
+ if hasUnrecordedRefusal { problem = nil }
return problem
}
}
@@ -167,7 +167,7 @@ public actor RefusalLog {
return kept.records
}
guard let read = BoundedRead.contents(at: url, maximum: readLimit) else {
- note(.unreadable)
+ note(.unreadable(BoundedRead.whyUnreadable(url, maximum: readLimit)))
return nil
}
let data = read.data
@@ -181,7 +181,7 @@ public actor RefusalLog {
// A row that a later version wrote, or that a hand edit broke, must not cost the other rows.
let readable = (try? decoder.decode([Row].self, from: data))?.compactMap(\.record) ?? []
guard let setAside = DamagedFile.setAside(url) else {
- note(.unreadable)
+ note(.unreadable(nil))
return nil
}
note(.damaged(setAside: setAside))
@@ -196,7 +196,7 @@ public actor RefusalLog {
private func note(_ problem: RefusalLogProblem?) {
if problem == nil {
if case .damaged(let setAside) = self.problem, !setAside.isMissing { return }
- if self.problem == .couldNotRecord { return }
+ if hasUnrecordedRefusal { return }
}
self.problem = problem
}
@@ -211,19 +211,28 @@ public actor RefusalLog {
}
}
- /// Writes `records`, less the oldest removals that wouldn't fit in what is read back, never one in `protected`.
+ private var hasUnrecordedRefusal: Bool {
+ if case .couldNotRecord = problem { true } else { false }
+ }
+
+ /// Writes `records`, less the oldest removals that wouldn't fit in what is read back, never one in `protected`,
+ /// and answers why it couldn't, or nil once it did.
@discardableResult
- private func write(_ records: [RefusalRecord], keeping protected: Set<UUID> = []) -> Bool {
+ private func write(_ records: [RefusalRecord], keeping protected: Set<UUID> = []) -> FileProblem? {
let encoder = JSONEncoder()
encoder.dateEncodingStrategy = LogTime.encoding
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
- guard let fitted = try? Batches.fitting(
- records, within: readLimit, batch: { $0.batch ?? $0.id }, date: \.date, keeping: protected,
- encode: { try encoder.encode($0) }
- ) else { return false }
- guard (try? PeelFolder.write(fitted.data, to: url)) != nil else { return false }
- // Every writer takes the lock, so the file here is the one just written.
- kept = FileIdentity.of(url).map { ($0, fitted.records) }
- return true
+ do {
+ let fitted = try Batches.fitting(
+ records, within: readLimit, batch: { $0.batch ?? $0.id }, date: \.date, keeping: protected,
+ encode: { try encoder.encode($0) }
+ )
+ try PeelFolder.write(fitted.data, to: url)
+ // Every writer takes the lock, so the file here is the one just written.
+ kept = FileIdentity.of(url).map { ($0, fitted.records) }
+ return nil
+ } catch {
+ return .failed(SystemError(error))
+ }
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swift
index 49928936..785dd6bd 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalLog.swift
@@ -6,12 +6,12 @@ public enum RemovalLogProblem: Sendable, Equatable {
/// The file could not be decoded. It was set aside under this name, and a new log was started with the rows
/// that could be read.
case damaged(setAside: URL)
- /// The file could not be read or set aside, so nothing new is being recorded.
- case unreadable
+ /// The file could not be read or set aside, so nothing new is being recorded; and why, when Peel knows.
+ case unreadable(FileProblem?)
/// The log could not be written, so the last removal is not recorded.
- case couldNotRecord
+ case couldNotRecord(FileProblem?)
/// The log could not be written after a Put Back or a Forget, so it still lists those records.
- case couldNotUpdate
+ case couldNotUpdate(FileProblem?)
}
/// The result of reading or changing the log. `records` is nil when the file was left
@@ -89,7 +89,7 @@ public actor RemovalLog {
guard !records.isEmpty else { return outcome(current()) }
guard let existing = current() else { return outcome(nil) }
let new = Set(records.map(\.batch))
- guard let updated = write(existing + records, keeping: new, orNote: .couldNotRecord) else {
+ guard let updated = write(existing + records, keeping: new, orNote: RemovalLogProblem.couldNotRecord) else {
journal.keep(records)
return outcome(nil)
}
@@ -100,7 +100,7 @@ public actor RemovalLog {
journal.forget(records.map(\.trashedItem))
}
// A removal that is recorded clears an earlier `.couldNotRecord`.
- if problem == .couldNotRecord { problem = nil }
+ if hasUnrecordedRemoval { problem = nil }
return outcome(updated)
}
}
@@ -135,7 +135,12 @@ public actor RemovalLog {
/// Whether History at `url` can be read, known without reading it: it is not there yet, or it opens as the file
/// it should be. A History that cannot be read is never written over, and nothing moves meanwhile.
public static func canBeRead(at url: URL = RemovalHistory.defaultURL) -> Bool {
- url.isMissing || BoundedRead.opens(url, maximum: maximumBytes)
+ readProblem(at: url) == nil
+ }
+
+ /// Why History at `url` can't be read, or nil when it can.
+ public static func readProblem(at url: URL = RemovalHistory.defaultURL) -> FileProblem? {
+ url.isMissing ? nil : BoundedRead.whyUnreadable(url, maximum: maximumBytes)
}
/// Why a removal couldn't be recorded in History at `url` now, or nil when it could: the folder it is written
@@ -176,7 +181,7 @@ public actor RemovalLog {
whileNoOtherProcessWrites {
guard let existing = current() else { return outcome(nil) }
let updated = existing.filter { !ids.contains($0.id) }
- return outcome(write(updated, orNote: .couldNotUpdate))
+ return outcome(write(updated, orNote: RemovalLogProblem.couldNotUpdate))
}
}
@@ -200,11 +205,15 @@ public actor RemovalLog {
private func note(_ problem: RemovalLogProblem?) {
if problem == nil {
if case .damaged = self.problem { return }
- if self.problem == .couldNotRecord { return }
+ if hasUnrecordedRemoval { return }
}
self.problem = problem
}
+ private var hasUnrecordedRemoval: Bool {
+ if case .couldNotRecord = problem { true } else { false }
+ }
+
/// The records on disk with every removal that stopped before recording itself taken in, or nil when the file
/// must not be replaced because it could not be read.
private func current() -> [RemovalRecord]? {
@@ -224,9 +233,8 @@ public actor RemovalLog {
var updated = records
if !interrupted.isEmpty {
let taken = Set(interrupted.map(\.batch))
- guard let written = write(records + interrupted, keeping: taken, orNote: .couldNotRecord) else {
- return records
- }
+ let written = write(records + interrupted, keeping: taken, orNote: RemovalLogProblem.couldNotRecord)
+ guard let written else { return records }
updated = written
RemovalTotals.change(at: totals) { $0.add(interrupted) }
}
@@ -247,7 +255,7 @@ public actor RemovalLog {
return kept.records
}
guard let read = BoundedRead.contents(at: url, maximum: readLimit) else {
- note(.unreadable)
+ note(.unreadable(BoundedRead.whyUnreadable(url, maximum: readLimit)))
return nil
}
let data = read.data
@@ -261,11 +269,13 @@ public actor RemovalLog {
// A row this version cannot read (written by a later version, or broken by hand) must not cost the rest.
let readable = (try? decoder.decode([Row].self, from: data))?.compactMap(\.record) ?? []
guard let setAside = DamagedFile.setAside(url) else {
- note(.unreadable)
+ note(.unreadable(nil))
return nil
}
note(.damaged(setAside: setAside))
- guard !readable.isEmpty, let written = write(readable, orNote: .damaged(setAside: setAside)) else { return [] }
+ guard !readable.isEmpty, let written = write(readable, orNote: { _ in .damaged(setAside: setAside) }) else {
+ return []
+ }
return written
}
@@ -281,7 +291,8 @@ public actor RemovalLog {
/// Writes `records`, less the oldest removals beyond `maximumRecords` or what is read back, never one in
/// `protected`, counts those it left out in the totals, and answers what it wrote, or nil when it couldn't.
private func write(
- _ records: [RemovalRecord], keeping protected: Set<UUID> = [], orNote failure: RemovalLogProblem
+ _ records: [RemovalRecord], keeping protected: Set<UUID> = [],
+ orNote failure: (FileProblem?) -> RemovalLogProblem
) -> [RemovalRecord]? {
let encoder = JSONEncoder()
encoder.dateEncodingStrategy = LogTime.encoding
@@ -301,7 +312,7 @@ public actor RemovalLog {
return fitted.records
} catch {
// An unrecorded removal is the most serious problem, so a later failure never replaces it.
- if problem != .couldNotRecord { note(failure) }
+ if !hasUnrecordedRemoval { note(failure(.failed(SystemError(error)))) }
return nil
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/BoundedRead.swift b/Packages/PeelCore/Sources/PeelCore/Support/BoundedRead.swift
index bf7fef5e..4a2d6c2d 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/BoundedRead.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/BoundedRead.swift
@@ -23,7 +23,7 @@ enum BoundedRead {
static func contents(
at url: URL, maximum: Int = maximumBytes, read: Read = { Darwin.read($0, $1, $2) }
) -> (data: Data, file: FileIdentity)? {
- guard let (descriptor, info) = openRegularFile(at: url, maximum: maximum) else { return nil }
+ guard case .success(let (descriptor, info)) = openRegularFile(at: url, maximum: maximum) else { return nil }
defer { close(descriptor) }
var data = Data()
@@ -44,7 +44,7 @@ enum BoundedRead {
/// The first `count` bytes of the regular file at `url`, or the whole file when it is shorter, whatever its size.
static func prefix(of url: URL, count: Int) -> Data? {
- guard let descriptor = openRegularFile(at: url, maximum: .max)?.descriptor else { return nil }
+ guard case .success(let (descriptor, _)) = openRegularFile(at: url, maximum: .max) else { return nil }
defer { close(descriptor) }
var buffer = [UInt8](repeating: 0, count: count)
@@ -64,35 +64,47 @@ enum BoundedRead {
return Data(buffer[0..<filled])
}
- /// What macOS answers when `url` is opened to be read, or nil when it opens: why a read found nothing.
- static func openError(of url: URL) -> SystemError? {
- let descriptor = open(url.path(percentEncoded: false), O_RDONLY | O_NONBLOCK | O_CLOEXEC)
- guard descriptor < 0 else {
+ /// Why `data(at:maximum:)` finds nothing at `url`, asked again: macOS's answer to opening it, or what stands
+ /// there. Nil when it opens as a regular file of at most `maximum` bytes.
+ static func whyUnreadable(_ url: URL, maximum: Int = maximumBytes) -> FileProblem? {
+ switch openRegularFile(at: url, maximum: maximum) {
+ case .success(let (descriptor, _)):
close(descriptor)
return nil
+ case .failure(let problem):
+ return problem
}
- return SystemError(domain: NSPOSIXErrorDomain, code: Int(errno))
}
/// Whether `url` opens as a regular file of at most `maximum` bytes, which is what `data(at:maximum:)` asks
/// before it reads.
static func opens(_ url: URL, maximum: Int = maximumBytes) -> Bool {
- guard let descriptor = openRegularFile(at: url, maximum: maximum)?.descriptor else { return false }
- close(descriptor)
- return true
+ whyUnreadable(url, maximum: maximum) == nil
}
/// A descriptor for the regular file at `url` when it is at most `maximum` bytes, which the caller closes, and
- /// what `fstat(2)` says of it.
- private static func openRegularFile(at url: URL, maximum: Int) -> (descriptor: Int32, info: stat)? {
+ /// what `fstat(2)` says of it, or why it isn't one.
+ private static func openRegularFile(
+ at url: URL, maximum: Int
+ ) -> Result<(descriptor: Int32, info: stat), FileProblem> {
let descriptor = open(url.path(percentEncoded: false), O_RDONLY | O_NONBLOCK | O_CLOEXEC)
- guard descriptor >= 0 else { return nil }
- var info = stat()
- guard fstat(descriptor, &info) == 0, info.st_mode & S_IFMT == S_IFREG, info.st_size <= maximum else {
- close(descriptor)
- return nil
+ guard descriptor >= 0 else {
+ return .failure(.failed(SystemError(domain: NSPOSIXErrorDomain, code: Int(errno))))
}
- return (descriptor, info)
+ var info = stat()
+ let problem: FileProblem? =
+ if fstat(descriptor, &info) != 0 {
+ .failed(SystemError(domain: NSPOSIXErrorDomain, code: Int(errno)))
+ } else if info.st_mode & S_IFMT != S_IFREG {
+ .notAFile
+ } else if info.st_size > maximum {
+ .tooLarge
+ } else {
+ nil
+ }
+ guard let problem else { return .success((descriptor, info)) }
+ close(descriptor)
+ return .failure(problem)
}
static func propertyList(at url: URL, maximum: Int = maximumBytes) -> [String: Any]? {
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/FileProblem.swift b/Packages/PeelCore/Sources/PeelCore/Support/FileProblem.swift
new file mode 100644
index 00000000..cc507b50
--- /dev/null
+++ b/Packages/PeelCore/Sources/PeelCore/Support/FileProblem.swift
@@ -0,0 +1,7 @@
+/// Why a file couldn't be read or written: what stands where it should be, or what macOS answered.
+public enum FileProblem: Error, Sendable, Hashable {
+ case notAFile
+ /// It is larger than Peel reads a file of its kind.
+ case tooLarge
+ case failed(SystemError)
+}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift
index ed863397..a02cf523 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift
@@ -511,9 +511,10 @@ struct HistoryCommandTests {
let logs = logs(in: directory)
try directory.file("Peel/refusals.json/kept.txt")
- await #expect(throws: CommandFailure.self) { try await printed(["history", "--refused"], from: logs) }
+ let failure = await #expect(throws: CommandFailure.self) { try await printed(["history", "--refused"], from: logs) }
await #expect(throws: CommandFailure.self) { try await printed(["history", "--refused", "--json"], from: logs) }
- #expect(RefusalLogProblem.unreadable.summary.contains("`peel history --refused --clear`"))
+ #expect(failure?.description.contains("`peel history --refused --clear`") == true)
+ #expect(failure?.description.hasSuffix(" Something other than a file, such as a folder, is where the file should be.") == true)
}
@Test func putsNothingBackWhileTheExclusionsCannotBeRead() async throws {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift
index f69cbf70..93b304a4 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift
@@ -252,7 +252,11 @@ struct RefusalLogTests {
try directory.setPermissions(0o700, of: "Peel")
await log.add([failure("/Users/me/b", .lastCopy)], source: "Editor", tool: "applications")
- #expect(opened.problem == .couldNotRecord, "opening History read the old file and cleared it unseen")
+ let refusedWrite = SystemError(domain: NSCocoaErrorDomain, code: NSFileWriteNoPermissionError)
+ #expect(
+ opened.problem == .couldNotRecord(.failed(refusedWrite)),
+ "opening History read the old file and cleared it unseen"
+ )
#expect(await log.load().problem == nil)
}
@@ -311,8 +315,9 @@ struct RefusalLogTests {
try FileManager.default.setAttributes([.posixPermissions: 0o644], ofItemAtPath: url.path(percentEncoded: false))
#expect(try Data(contentsOf: url) == Data("[]".utf8), "an unreadable record was written over")
- #expect(problem == .unreadable)
- #expect(outcome.problem == .unreadable && outcome.records == nil)
+ let closed = FileProblem.failed(SystemError(domain: NSPOSIXErrorDomain, code: Int(EACCES)))
+ #expect(problem == .unreadable(closed))
+ #expect(outcome.problem == .unreadable(closed) && outcome.records == nil)
}
/// A refusal that could not be written down is said, rather than lost without a word.
@@ -325,7 +330,8 @@ struct RefusalLogTests {
let problem = await RefusalLog(url: folder.appending(path: "refusals.json"))
.add([failure("/Users/me/a", .lastCopy)], source: "Editor", tool: "applications")
- #expect(problem == .couldNotRecord)
+ let refusedWrite = SystemError(domain: NSCocoaErrorDomain, code: NSFileWriteNoPermissionError)
+ #expect(problem == .couldNotRecord(.failed(refusedWrite)))
}
/// A record in a folder that cannot be searched may be there, so it is not called cleared.
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift
index 41b157eb..f6e31ed1 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift
@@ -300,8 +300,9 @@ struct RemovalHistoryTests {
try directory.setPermissions(0o500, of: "Peel")
defer { try? directory.setPermissions(0o755, of: "Peel") }
- #expect(await log.add([Self.record(batch: UUID())]).problem == .couldNotRecord)
- #expect(await log.load().problem == .couldNotRecord, "reading the older file took the notice away")
+ let refused = FileProblem.failed(SystemError(domain: NSCocoaErrorDomain, code: NSFileWriteNoPermissionError))
+ #expect(await log.add([Self.record(batch: UUID())]).problem == .couldNotRecord(refused))
+ #expect(await log.load().problem == .couldNotRecord(refused), "reading the older file took the notice away")
try directory.setPermissions(0o755, of: "Peel")
#expect(await log.add([Self.record(batch: UUID())]).problem == nil, "a removal that was recorded is what ends it")
@@ -317,7 +318,10 @@ struct RemovalHistoryTests {
try directory.setPermissions(0o500, of: "Peel")
defer { try? directory.setPermissions(0o755, of: "Peel") }
- #expect(await log.remove([record.id]).problem == .couldNotUpdate)
+ #expect(
+ await log.remove([record.id]).problem
+ == .couldNotUpdate(.failed(SystemError(domain: NSCocoaErrorDomain, code: NSFileWriteNoPermissionError)))
+ )
}
/// A file that cannot even be read cannot be copied out of the way, so nothing is written at all.
@@ -330,7 +334,7 @@ struct RemovalHistoryTests {
let outcome = await RemovalLog(url: url).add([Self.record(batch: UUID())])
#expect(outcome.records == nil, "an unreadable log was replaced anyway")
- #expect(outcome.problem == .unreadable)
+ #expect(outcome.problem == .unreadable(.failed(SystemError(domain: NSPOSIXErrorDomain, code: Int(EACCES)))))
}
/// Whether History can be read is known without reading it, so a removal can be refused before anything moves:
@@ -345,6 +349,7 @@ struct RemovalHistoryTests {
try directory.setPermissions(0, of: "Peel/removals.json")
#expect(!RemovalLog.canBeRead(at: url), "a file Peel cannot open")
+ #expect(RemovalLog.readProblem(at: url) == .failed(SystemError(domain: NSPOSIXErrorDomain, code: Int(EACCES))))
try directory.setPermissions(0o644, of: "Peel/removals.json")
try directory.setPermissions(0o600, of: "Peel")
@@ -358,7 +363,8 @@ struct RemovalHistoryTests {
let url = try directory.file("Peel/removals.json", contents: Data("[]".utf8))
try directory.setPermissions(0, of: "Peel/removals.json")
let log = RemovalLog(url: url)
- #expect(await log.load().problem == .unreadable)
+ let closed = SystemError(domain: NSPOSIXErrorDomain, code: Int(EACCES))
+ #expect(await log.load().problem == .unreadable(.failed(closed)))
let startedOver = await log.startOver()
@@ -440,7 +446,7 @@ struct RemovalHistoryTests {
let outcome = await RemovalLog(url: url).add([Self.record(batch: UUID())])
#expect(outcome.records == nil)
- #expect(outcome.problem == .unreadable)
+ #expect(outcome.problem == .unreadable(.failed(SystemError(domain: NSPOSIXErrorDomain, code: Int(EACCES)))))
}
/// History showing "3 items" for a removal that touched twelve is worse than showing nothing: the user
diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swift
index 82778e94..390caecb 100644
--- a/Peel/Model/RemovalHistoryStore.swift
+++ b/Peel/Model/RemovalHistoryStore.swift
@@ -167,9 +167,9 @@ final class RemovalHistoryStore {
private var toldRefusalsNoLongerListed: Int?
/// The count History's page said last, read from the preferences once History has left something out.
private var toldNoLongerListed: Int?
- /// Whether History cannot be read, which holds every removal back, as the Trash service does. Known without
- /// reading it: at launch, when Peel comes forward, and with every read or change of History.
- private(set) var isUnreadable = false
+ /// Why History cannot be read, which holds every removal back, as the Trash service does; nil while it can. Known
+ /// without reading it: at launch, when Peel comes forward, and with every read or change of History.
+ private(set) var readProblem: FileProblem?
/// Why History cannot be written, as on a full disk, which holds every removal back too. Known the same way.
private(set) var writeProblem: HistoryWriteProblem?
private(set) var isRestoring = false
@@ -256,13 +256,17 @@ final class RemovalHistoryStore {
/// Whether History was read and lists nothing. One that can't be read now isn't known to be empty.
var isKnownEmpty: Bool {
- hasLoaded && batches.isEmpty && refusalBatches.isEmpty && shownProblem != .unreadable
+ guard hasLoaded, batches.isEmpty, refusalBatches.isEmpty else { return false }
+ if case .unreadable = shownProblem { return false }
+ return true
}
+ var isUnreadable: Bool { readProblem != nil }
+
/// The problem History's page shows: that History cannot be read, as soon as that is known, otherwise what the
/// last read or change of it met.
var shownProblem: RemovalLogProblem? {
- isUnreadable ? .unreadable : problem
+ readProblem.map { .unreadable($0) } ?? problem
}
/// How many older removals History no longer lists, while its page has not said that count yet.
@@ -294,9 +298,9 @@ final class RemovalHistoryStore {
func checkReadability() async {
let problem = await log.setAsideAnUnreadableJournal()
if self.problem != problem { self.problem = problem }
- let unreadable = !RemovalLog.canBeRead(at: log.url)
- let writeProblem = unreadable ? nil : RemovalLog.writeProblem(at: log.url)
- if isUnreadable != unreadable { isUnreadable = unreadable }
+ let readProblem = RemovalLog.readProblem(at: log.url)
+ let writeProblem = readProblem == nil ? RemovalLog.writeProblem(at: log.url) : nil
+ if self.readProblem != readProblem { self.readProblem = readProblem }
if self.writeProblem != writeProblem { self.writeProblem = writeProblem }
}
diff --git a/Peel/Views/History/HistoryList.swift b/Peel/Views/History/HistoryList.swift
index 3e421ecd..849a3062 100644
--- a/Peel/Views/History/HistoryList.swift
+++ b/Peel/Views/History/HistoryList.swift
@@ -155,24 +155,24 @@ private struct HistoryProblemNotice: View {
NSWorkspace.shared.activateFileViewerSelecting([setAside])
}
}
- case .unreadable:
+ case .unreadable(let why):
Notice(
title: Text("The record of past removals can’t be read"),
- detail: Text("Until it can read the record, or you start over, Peel removes nothing, because anything it moved now couldn’t be put back. Starting over keeps the old file beside a new one. Items it lists can then only be dragged back out of the Trash in Finder.")
+ detail: Text(verbatim: why.said(after: String(localized: "Until it can read the record, or you start over, Peel removes nothing, because anything it moved now couldn’t be put back. Starting over keeps the old file beside a new one. Items it lists can then only be dragged back out of the Trash in Finder."), about: history.historyFile))
) {
StartOverButton(file: history.historyFile, startedOver: "Started History over.") {
await history.startOver()
}
}
- case .couldNotRecord:
+ case .couldNotRecord(let why):
Notice(
title: Text("The last removal couldn’t be recorded"),
- detail: Text("The items are in the Trash. You can drag them back out in Finder.")
+ detail: Text(verbatim: why.said(after: String(localized: "The items are in the Trash. You can drag them back out in Finder."), about: history.historyFile))
) { EmptyView() }
- case .couldNotUpdate:
+ case .couldNotUpdate(let why):
Notice(
title: Text("History couldn’t be updated"),
- detail: Text("What you put back or forgot may still be listed here, because the record couldn’t be saved.")
+ detail: Text(verbatim: why.said(after: String(localized: "What you put back or forgot may still be listed here, because the record couldn’t be saved."), about: history.historyFile))
) { EmptyView() }
}
}
@@ -194,19 +194,19 @@ private struct RefusalProblemNotice: View {
NSWorkspace.shared.activateFileViewerSelecting([setAside])
}
}
- case .unreadable:
+ case .unreadable(let why):
Notice(
title: Text("The Not Moved list can’t be read"),
- detail: Text("Until you start the list over, Peel adds nothing to it, since it is the only record of what stayed. Starting over keeps the old file beside a new one.")
+ detail: Text(verbatim: why.said(after: String(localized: "Until you start the list over, Peel adds nothing to it, since it is the only record of what stayed. Starting over keeps the old file beside a new one."), about: history.refusalsFile))
) {
StartOverButton(file: history.refusalsFile, startedOver: "Started the Not Moved list over.") {
await history.startOverRefusals()
}
}
- case .couldNotRecord:
+ case .couldNotRecord(let why):
Notice(
title: Text("The Not Moved list couldn’t be saved"),
- detail: Text("What stayed in the last removal is where it was, but it isn’t listed here.")
+ detail: Text(verbatim: why.said(after: String(localized: "What stayed in the last removal is where it was, but it isn’t listed here."), about: history.refusalsFile))
) { EmptyView() }
}
}
diff --git a/Peel/Views/Home/HomePermissionsView.swift b/Peel/Views/Home/HomePermissionsView.swift
index b8198004..eb40a0dc 100644
--- a/Peel/Views/Home/HomePermissionsView.swift
+++ b/Peel/Views/Home/HomePermissionsView.swift
@@ -234,10 +234,10 @@ struct HomePermissionsContent: View {
Button("Open Peel Settings") { SettingsPane.exclusions.open(with: openSettings) }
.buttonStyle(.sticker(fill: Album.redFill, size: 11.5))
}
- } else if held == .historyUnreadable {
+ } else if case .historyUnreadable(let why) = held {
Notice(
title: Text("Peel couldn’t read History"),
- detail: Text("Peel removes nothing until you start History over, so that everything it moves can be put back."),
+ detail: Text(verbatim: why.said(after: String(localized: "Peel removes nothing until you start History over, so that everything it moves can be put back."), about: history.historyFile)),
isAlbum: true
) {
Button("Open History") { Navigator.shared.requestedTool = .history }
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index f6575f79..d645bdda 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -258,6 +258,25 @@ extension AppInspector.Unreadable {
}
}
+extension FileProblem {
+ /// `sentence`, then why the file at `url` couldn't be read or saved.
+ func said(after sentence: String, about url: URL) -> String {
+ 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 .failed(let error): String(localized: "macOS answered: \(error.description(of: url))")
+ }
+ return [sentence, why].joined(separator: " ")
+ }
+}
+
+extension FileProblem? {
+ /// `sentence`, then why the file at `url` couldn't be read or saved, when that is known.
+ func said(after sentence: String, about url: URL) -> String {
+ self?.said(after: sentence, about: url) ?? sentence
+ }
+}
+
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 75d57e88..3f46aad0 100644
--- a/Peel/Views/RemovalsHeldBanner.swift
+++ b/Peel/Views/RemovalsHeldBanner.swift
@@ -5,16 +5,16 @@ import SwiftUI
/// Exclusions not read yet are none of these, since they are read as Peel starts.
enum MovesHeld: Equatable {
case exclusionsUnreadable
- case historyUnreadable
+ case historyUnreadable(FileProblem)
case historyUnwritable(HistoryWriteProblem)
static func reason(
- exclusionsUnreadable: Bool, historyUnreadable: Bool, historyUnwritable: HistoryWriteProblem?,
+ exclusionsUnreadable: Bool, historyUnreadable: FileProblem?, historyUnwritable: HistoryWriteProblem?,
recordsInHistory: Bool = true
) -> MovesHeld? {
if exclusionsUnreadable { return .exclusionsUnreadable }
guard recordsInHistory else { return nil }
- if historyUnreadable { return .historyUnreadable }
+ if let historyUnreadable { return .historyUnreadable(historyUnreadable) }
return historyUnwritable.map(MovesHeld.historyUnwritable)
}
@@ -23,7 +23,7 @@ enum MovesHeld: Equatable {
exclusions: ExclusionsStore, history: RemovalHistoryStore, recordsInHistory: Bool = true
) -> MovesHeld? {
reason(
- exclusionsUnreadable: exclusions.exclusions.isUnreadable, historyUnreadable: history.isUnreadable,
+ exclusionsUnreadable: exclusions.exclusions.isUnreadable, historyUnreadable: history.readProblem,
historyUnwritable: history.writeProblem, recordsInHistory: recordsInHistory
)
}
@@ -51,10 +51,10 @@ struct RemovalsHeldBanner: View {
}
.padding(.vertical, 6)
.listRowSeparator(.hidden)
- } else if held == .historyUnreadable, !isOnHistoryPage {
+ } else if case .historyUnreadable(let why) = held, !isOnHistoryPage {
Notice(
title: Text("Peel couldn’t read History"),
- detail: Text("Peel removes nothing until you start History over, so that everything it moves can be put back.")
+ detail: Text(verbatim: why.said(after: String(localized: "Peel removes nothing until you start History over, so that everything it moves can be put back."), about: history.historyFile))
) {
Button("Open History") {
Navigator.shared.requestedTool = .history
diff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swift
index 4f3c8e12..6d835313 100644
--- a/Peel/Views/Settings/SettingsView.swift
+++ b/Peel/Views/Settings/SettingsView.swift
@@ -449,8 +449,8 @@ private struct GeneralSettingsView: View {
Text("Peel removes nothing and puts nothing back until you start the list over in Settings.")
.font(.callout)
.foregroundStyle(.secondary)
- } else if history.isUnreadable {
- Text("Peel removes nothing until you start History over, so that everything it moves can be put back.")
+ } else if let why = history.readProblem {
+ Text(verbatim: why.said(after: String(localized: "Peel removes nothing until you start History over, so that everything it moves can be put back."), about: history.historyFile))
.font(.callout)
.foregroundStyle(.secondary)
} else if let problem = history.writeProblem {
diff --git a/PeelTests/MovesHeldTests.swift b/PeelTests/MovesHeldTests.swift
index 5886e48c..e2943b35 100644
--- a/PeelTests/MovesHeldTests.swift
+++ b/PeelTests/MovesHeldTests.swift
@@ -9,21 +9,21 @@ struct MovesHeldTests {
@Test func namesWhatKeepsEveryMoveBack() {
func reason(_ exclusions: Bool, _ history: Bool, _ writing: Bool) -> MovesHeld? {
MovesHeld.reason(
- exclusionsUnreadable: exclusions, historyUnreadable: history,
+ exclusionsUnreadable: exclusions, historyUnreadable: history ? .notAFile : nil,
historyUnwritable: writing ? Self.full : nil
)
}
#expect(reason(false, false, false) == nil)
#expect(reason(true, true, true) == .exclusionsUnreadable)
- #expect(reason(false, true, true) == .historyUnreadable)
+ #expect(reason(false, true, true) == .historyUnreadable(.notAFile))
#expect(reason(false, false, true) == .historyUnwritable(Self.full))
}
@Test func anActionHistoryDoesntRecordWaitsOnlyForTheExclusions() {
func reason(_ exclusions: Bool, _ history: Bool, _ writing: Bool) -> MovesHeld? {
MovesHeld.reason(
- exclusionsUnreadable: exclusions, historyUnreadable: history,
+ exclusionsUnreadable: exclusions, historyUnreadable: history ? .notAFile : nil,
historyUnwritable: writing ? Self.full : nil, recordsInHistory: false
)
}
diff --git a/PeelTests/RemovalHistoryStoreTests.swift b/PeelTests/RemovalHistoryStoreTests.swift
index 8a9d6e2a..cc684594 100644
--- a/PeelTests/RemovalHistoryStoreTests.swift
+++ b/PeelTests/RemovalHistoryStoreTests.swift
@@ -133,7 +133,7 @@ struct RemovalHistoryStoreTests {
await history.load()
#expect(history.hasLoaded && history.batches.isEmpty)
- #expect(history.shownProblem == .unreadable)
+ #expect(history.shownProblem == .unreadable(.notAFile))
#expect(!history.isKnownEmpty)
}
@@ -205,7 +205,8 @@ struct RemovalHistoryStoreTests {
await history.restore(history.records, canUseHelper: false)
- #expect(history.problem == .couldNotUpdate)
+ let refusedWrite = SystemError(domain: NSCocoaErrorDomain, code: NSFileWriteNoPermissionError)
+ #expect(history.problem == .couldNotUpdate(.failed(refusedWrite)))
#expect(history.trashLooks == looks + 1, "the page kept saying it is in the Trash")
}
@@ -346,8 +347,8 @@ struct RemovalHistoryStoreTests {
let startedOver = await history.startOver()
let startedRefusalsOver = await history.startOverRefusals()
- #expect(startedOver == .couldNotSetAside && history.shownProblem == .unreadable)
- #expect(startedRefusalsOver == .couldNotSetAside && history.refusalProblem == .unreadable)
+ #expect(startedOver == .couldNotSetAside && history.shownProblem == .unreadable(.notAFile))
+ #expect(startedRefusalsOver == .couldNotSetAside && history.refusalProblem == .unreadable(.notAFile))
}
@Test func startsOverANotMovedListItCannotRead() async throws {
@@ -361,7 +362,7 @@ struct RemovalHistoryStoreTests {
knowsTheExclusions: { true }
)
await history.load()
- #expect(history.refusalProblem == .unreadable)
+ #expect(history.refusalProblem == .unreadable(.notAFile))
await history.startOverRefusals()
@@ -392,7 +393,8 @@ struct RemovalHistoryStoreTests {
await history.load()
- #expect(history.refusalProblem == .couldNotRecord)
+ let refusedWrite = SystemError(domain: NSCocoaErrorDomain, code: NSFileWriteNoPermissionError)
+ #expect(history.refusalProblem == .couldNotRecord(.failed(refusedWrite)))
}
@Test func aReadThatFindsNothingNewChangesNothing() async throws {