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 when Start Over couldn't set the old file aside

Țugui Dragoșea0055f64083
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 1643eb47..3433b4f4 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -103631,6 +103631,112 @@
}
}
},
+ "Nothing changed. Check that Peel can write to its folder in Application Support, then try again." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nic se nezměnilo. Zkontrolujte, zda Peel může zapisovat do své složky v Application Support, a zkuste to znovu."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Es wurde nichts geändert. Prüfe, ob Peel in seinen Ordner in Application Support schreiben kann, und versuche es dann erneut."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "No ha cambiado nada. Comprueba que Peel pueda escribir en su carpeta de Application Support y vuelve a intentarlo."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Rien n’a changé. Vérifiez que Peel peut écrire dans son dossier situé dans Application Support, puis réessayez."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non è cambiato nulla. Verifica che Peel possa scrivere nella sua cartella in Application Support, poi riprova."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "何も変更されていません。Application SupportにあるPeelのフォルダにPeelが書き込めることを確認してから、やり直してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "아무것도 변경되지 않았습니다. Peel이 Application Support에 있는 자신의 폴더에 쓸 수 있는지 확인한 다음 다시 시도하십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Er is niets gewijzigd. Controleer of Peel naar de eigen map in Application Support kan schrijven en probeer het opnieuw."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nic się nie zmieniło. Sprawdź, czy Peel może zapisywać w swoim folderze w Application Support, a następnie spróbuj ponownie."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nada mudou. Verifique se o Peel consegue gravar na pasta dele em Application Support e tente novamente."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nu s‑a schimbat nimic. Verificați dacă Peel poate scrie în dosarul său din Application Support, apoi încercați din nou."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ничего не изменилось. Убедитесь, что Peel может записывать в свою папку в Application Support, а затем повторите попытку."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Inget ändrades. Kontrollera att Peel kan skriva till sin mapp i Application Support och försök sedan igen."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Hiçbir şey değişmedi. Peel’in Application Support içindeki klasörüne yazabildiğini denetleyin, ardından yeniden deneyin."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Нічого не змінено. Перевірте, чи може Peel записувати у свою папку в Application Support, та спробуйте ще раз."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未做任何更改。请检查Peel能否写入它在Application Support中的文件夹,然后重试。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "沒有任何變更。請確認Peel可以寫入它在Application Support中的檔案夾,然後再試一次。"
+ }
+ }
+ }
+ },
"Nothing else on this Mac opens these." : {
"localizations" : {
"cs" : {
@@ -119148,6 +119254,112 @@
}
}
},
+ "Peel couldn’t set the old file aside" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemohl odložit starý soubor stranou"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel konnte die alte Datei nicht beiseitelegen"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no ha podido apartar el archivo antiguo"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel n’a pas pu mettre l’ancien fichier de côté"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non è riuscito a mettere da parte il vecchio file"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelは古いファイルを別に保管できませんでした"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel이 이전 파일을 따로 보관할 수 없음"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kon het oude bestand niet apart zetten"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie mógł odłożyć na bok starego pliku"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não conseguiu guardar o arquivo antigo à parte"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu a putut pune deoparte fișierul vechi"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не удалось сохранить старый файл отдельно"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kunde inte lägga undan den gamla filen"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel eski dosyayı bir kenara ayıramadı"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не вдалося відкласти старий файл"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel未能将旧文件移到一旁"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel無法將舊檔案移到一旁"
+ }
+ }
+ }
+ },
"Peel couldn’t write to History, because the disk is full or Peel’s folder can’t be written, and it moves nothing it can’t put back." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift
index cbd91e88..edf812d6 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift
@@ -65,7 +65,7 @@ public actor RefusalLog {
static let maximumRecords = 5_000
static let maximumBytes = 16 * 1_024 * 1_024
- public let url: URL
+ public nonisolated let url: URL
/// What was last read or written, kept while the file stays the same, as in `RemovalLog`.
private var kept: (file: FileIdentity, records: [RefusalRecord])?
private var problem: RefusalLogProblem?
diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swift
index ea3b9abc..f7bdf711 100644
--- a/Peel/Model/RemovalHistoryStore.swift
+++ b/Peel/Model/RemovalHistoryStore.swift
@@ -255,18 +255,25 @@ final class RemovalHistoryStore {
}
/// Keeps a History that cannot be read beside a new one, and records again.
- func startOver() async {
+ @discardableResult
+ func startOver() async -> Bool {
let startedOver = await log.startOver()
await apply(await log.load())
if startedOver { announcing(AttributedString(localized: "Started History over.")) }
+ return startedOver
}
- func startOverRefusals() async {
+ @discardableResult
+ func startOverRefusals() async -> Bool {
let startedOver = await refusals.startOver()
await loadRefusals()
if startedOver { announcing(AttributedString(localized: "Started the Not Moved list over.")) }
+ return startedOver
}
+ var historyFile: URL { log.url }
+ var refusalsFile: URL { refusals.url }
+
private func loadRefusals() async {
await showRefusals(await refusals.load())
}
diff --git a/Peel/Views/History/HistoryList.swift b/Peel/Views/History/HistoryList.swift
index 70748317..596ec97f 100644
--- a/Peel/Views/History/HistoryList.swift
+++ b/Peel/Views/History/HistoryList.swift
@@ -133,8 +133,8 @@ private struct HistoryProblemNotice: View {
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.")
) {
- Button("Start Over") {
- Task { await history.startOver() }
+ StartOverButton(file: history.historyFile) {
+ await history.startOver() || history.shownProblem != .unreadable
}
}
case .couldNotRecord:
@@ -172,8 +172,8 @@ private struct RefusalProblemNotice: View {
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.")
) {
- Button("Start Over") {
- Task { await history.startOverRefusals() }
+ StartOverButton(file: history.refusalsFile) {
+ await history.startOverRefusals() || history.refusalProblem != .unreadable
}
}
case .couldNotRecord:
@@ -185,6 +185,27 @@ private struct RefusalProblemNotice: View {
}
}
+/// Starts a file that can't be read over, and says so when its old copy couldn't be set aside, which leaves
+/// everything as it was.
+private struct StartOverButton: View {
+ let file: URL
+ /// Starts over and answers whether the file can be used now.
+ let startOver: () async -> Bool
+ @State private var couldNotSetAside = false
+
+ var body: some View {
+ Button("Start Over") {
+ Task { couldNotSetAside = !(await startOver()) }
+ }
+ .alert("Peel couldn’t set the old file aside", isPresented: $couldNotSetAside) {
+ Button("Show in Finder") { NSWorkspace.shared.activateFileViewerSelecting([file]) }
+ Button("OK", role: .cancel) {}
+ } message: {
+ Text("Nothing changed. Check that Peel can write to its folder in Application Support, then try again.")
+ }
+ }
+}
+
private struct HistoryBatchRow: View {
let batch: RemovalBatch
diff --git a/PeelTests/RemovalHistoryStoreTests.swift b/PeelTests/RemovalHistoryStoreTests.swift
index 53a33447..3beeefc8 100644
--- a/PeelTests/RemovalHistoryStoreTests.swift
+++ b/PeelTests/RemovalHistoryStoreTests.swift
@@ -108,6 +108,30 @@ struct RemovalHistoryStoreTests {
#expect(heard.words == ["Started History over.", "Started the Not Moved list over."])
}
+ @Test func saysWhenStartingOverCouldNotSetTheOldFileAside() async throws {
+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")
+ let path = folder.path(percentEncoded: false)
+ try FileManager.default.createDirectory(at: folder.appending(path: "removals.json"), withIntermediateDirectories: true)
+ try FileManager.default.createDirectory(at: folder.appending(path: "refusals.json"), withIntermediateDirectories: true)
+ try FileManager.default.setAttributes([.posixPermissions: 0o500], ofItemAtPath: path)
+ defer {
+ try? FileManager.default.setAttributes([.posixPermissions: 0o700], ofItemAtPath: path)
+ try? FileManager.default.removeItem(at: folder)
+ }
+ let history = RemovalHistoryStore(
+ log: RemovalLog(url: folder.appending(path: "removals.json")),
+ refusals: RefusalLog(url: folder.appending(path: "refusals.json")),
+ knowsTheExclusions: { true }
+ )
+ await history.load()
+
+ let startedOver = await history.startOver()
+ let startedRefusalsOver = await history.startOverRefusals()
+
+ #expect(!startedOver && history.shownProblem == .unreadable)
+ #expect(!startedRefusalsOver && history.refusalProblem == .unreadable)
+ }
+
@Test func startsOverANotMovedListItCannotRead() async throws {
let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")
defer { try? FileManager.default.removeItem(at: folder) }