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.

Read This Belongs To's choices without writing, and say when one can't be saved

Țugui Dragoș5be17363642f
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 92e9fe07..8c48d40c 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -115840,6 +115840,112 @@
}
}
},
+ "Peel can’t read its list of the orphaned files you said belong to an app, so it lists them all. Start the list over in Settings > Exclusions." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemůže přečíst svůj seznam osiřelých souborů, u kterých jste uvedli, že patří některé aplikaci, a proto je zobrazuje všechny. Začněte seznam znovu v Nastavení > Výjimky."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kann seine Liste der verwaisten Dateien, die laut deiner Angabe zu einer App gehören, nicht lesen, daher werden sie alle angezeigt. Beginne die Liste in den Einstellungen unter „Ausschlüsse“ neu."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no puede leer su lista de los archivos huérfanos que has indicado que pertenecen a una app, así que los muestra todos. Vuelve a empezar la lista en Ajustes > Exclusiones."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel ne peut pas lire sa liste des fichiers orphelins que vous avez attribués à une app : il les liste donc tous. Recommencez la liste dans Réglages > Exclusions."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non riesce a leggere il suo elenco dei file orfani che hai indicato come appartenenti a un’app, quindi li elenca tutti. Ricomincia l’elenco da capo in Impostazioni > Esclusioni."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelは、アプリに属すると指定した孤立ファイルのリストを読み取れないため、それらをすべて表示します。“設定”>“除外”でリストを最初からやり直してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel이 앱의 소유로 지정한 주인 없는 파일 목록을 읽을 수 없으므로 해당 파일을 모두 나열합니다. 설정 > 제외 항목에서 목록을 처음부터 다시 시작하십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan zijn lijst van verweesde bestanden die volgens jou bij een app horen, niet lezen, dus toont Peel ze allemaal. Begin in Instellingen > Uitsluitingen opnieuw met de lijst."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie może odczytać swojej listy osieroconych plików wskazanych przez Ciebie jako należące do aplikacji, więc wyświetla je wszystkie. Zacznij tę listę od nowa w Ustawieniach > Wykluczenia."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não consegue ler a lista dos arquivos órfãos que você indicou como pertencentes a um app, então lista todos eles. Recomece a lista em Ajustes > Exclusões."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu își poate citi lista fișierelor orfane pe care le‑ați atribuit unei aplicații, așa că le listează pe toate. Reîncepeți lista în Configurări > Excluderi."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не удается прочитать свой список осиротевших файлов, которые Вы отметили как принадлежащие приложению, поэтому он показывает их все. Начните список заново в разделе «Настройки» > «Исключения»."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan inte läsa sin lista över de övergivna filer som du har angett hör till en app, så Peel listar dem alla. Börja om listan i Inställningar > Undantag."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel, bir uygulamaya ait olduğunu söylediğiniz sahipsiz dosyalar listesini okuyamıyor, bu yüzden hepsini listeliyor. Listeyi Ayarlar > Hariç Tutulanlar’da baştan başlatın."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не може прочитати свій список покинутих файлів, які, за вашими словами, належать програмі, тож показує їх усі. Почніть список наново в розділі Параметри > Винятки."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel无法读取你标为属于某个App的孤立文件的列表,因此会将它们全部列出。请在“设置”>“排除项”中重新开始建立该列表。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel無法讀取你指定屬於某個App的孤立檔案列表,因此會將它們全部列出。請在「設定」>「排除項目」中重新開始此列表。"
+ }
+ }
+ }
+ },
"Peel can’t read its record of who signs your apps" : {
"localizations" : {
"cs" : {
@@ -116052,6 +116158,112 @@
}
}
},
+ "Peel can’t read this list, so Orphaned Files lists these files again. Starting over keeps the old list beside a new one." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemůže přečíst tento seznam, takže stránka Osiřelé soubory tyto soubory znovu zobrazuje. Když začnete znovu, starý seznam se ponechá vedle nového."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kann diese Liste nicht lesen, daher zeigt die Seite „Verwaiste Dateien“ diese Dateien wieder an. Wenn du neu beginnst, bleibt die alte Liste neben einer neuen erhalten."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no puede leer esta lista, así que la página Archivos huérfanos vuelve a mostrar estos archivos. Al volver a empezar, la lista antigua se conserva junto a una nueva."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel ne peut pas lire cette liste : la page Fichiers orphelins liste donc à nouveau ces fichiers. Si vous recommencez, l’ancienne liste est conservée à côté d’une nouvelle."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non riesce a leggere questo elenco, quindi “File orfani” elenca di nuovo questi file. Se ricominci da capo, il vecchio elenco viene conservato accanto a uno nuovo."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelはこのリストを読み取れないため、“孤立ファイル”にはこれらのファイルが再び表示されます。最初からやり直すと、古いリストは新しいリストの横に保管されます。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel이 이 목록을 읽을 수 없으므로 주인 없는 파일 페이지에 이 파일들이 다시 나열됩니다. 처음부터 다시 시작하면 이전 목록은 새 목록 옆에 보관됩니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan deze lijst niet lezen, dus toont de pagina 'Verweesde bestanden' deze bestanden weer. Als je opnieuw begint, wordt de oude lijst naast een nieuwe lijst bewaard."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie może odczytać tej listy, więc strona Osierocone pliki znowu wyświetla te pliki. Gdy zaczniesz od nowa, stara lista zostanie zachowana obok nowej."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não consegue ler esta lista, então a página Arquivos Órfãos volta a listar esses arquivos. Ao recomeçar, a lista antiga é guardada ao lado de uma nova."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu poate citi această listă, așa că pagina Fișiere orfane listează din nou aceste fișiere. Dacă reîncepeți lista, cea veche este păstrată lângă una nouă."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не удается прочитать этот список, поэтому раздел «Осиротевшие файлы» снова показывает эти файлы. Если начать заново, старый список сохранится рядом с новым."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan inte läsa den här listan, så sidan Övergivna filer listar de här filerna igen. När du börjar om sparas den gamla listan bredvid en ny."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel bu listeyi okuyamıyor, bu yüzden Sahipsiz Dosyalar bu dosyaları yeniden listeliyor. Baştan başladığınızda eski liste yeni bir listenin yanında saklanır."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не може прочитати цей список, тож розділ «Покинуті файли» знову показує ці файли. Коли ви починаєте наново, старий список зберігається поруч із новим."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel无法读取此列表,因此“孤立文件”会再次列出这些文件。重新开始会将旧列表保留在新列表旁边。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel無法讀取此列表,因此「孤立檔案」會再次列出這些檔案。重新開始時,舊列表會保留在新列表旁邊。"
+ }
+ }
+ }
+ },
"Peel can’t run this file." : {
"localizations" : {
"cs" : {
@@ -117218,6 +117430,112 @@
}
}
},
+ "Peel couldn’t list these files again" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemohl tyto soubory znovu zobrazit"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel konnte diese Dateien nicht wieder anzeigen"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no ha podido volver a mostrar estos archivos"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel n’a pas pu lister à nouveau ces fichiers"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non è riuscito a elencare di nuovo questi file"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelはこれらのファイルを再び表示できませんでした"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel이 이 파일들을 다시 나열할 수 없음"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kon deze bestanden niet opnieuw tonen"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie mógł ponownie wyświetlić tych plików"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não conseguiu voltar a listar estes arquivos"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu a putut lista din nou aceste fișiere"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не удалось снова показать эти файлы в разделе «Осиротевшие файлы»"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kunde inte lista de här filerna igen"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel bu dosyaları yeniden listeleyemedi"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не вдалося знову показати ці файли"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel未能再次列出这些文件"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel無法再次列出這些檔案"
+ }
+ }
+ }
+ },
"Peel couldn’t look in ^[%lld folder](inflect: true)." : {
"localizations" : {
"cs" : {
@@ -119148,6 +119466,112 @@
}
}
},
+ "Peel couldn’t save that these files belong to %@" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemohl uložit, že tyto soubory patří aplikaci %@"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel konnte nicht sichern, dass diese Dateien zu „%@“ gehören"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no ha podido guardar que estos archivos pertenecen a %@"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel n’a pas pu enregistrer l’attribution de ces fichiers à %@"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non è riuscito a registrare che questi file appartengono a %@"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelは、これらのファイルが“%@”に属することを保存できませんでした"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel이 이 파일들을 ‘%@’의 소유로 지정한 내용을 저장할 수 없음"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kon niet bewaren dat deze bestanden bij %@ horen"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie mógł zachować informacji, że te pliki należą do aplikacji %@"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não conseguiu registrar que estes arquivos pertencem a %@"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu a putut salva faptul că aceste fișiere aparțin aplicației %@"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не удалось сохранить, что эти файлы принадлежат приложению «%@»"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kunde inte spara att de här filerna hör till %@"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel bu dosyaların %@ uygulamasına ait olduğunu kaydedemedi"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не вдалося зберегти запис про те, що ці файли належать програмі «%@»"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel未能保存这些文件属于“%@”的信息"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel無法記錄這些檔案屬於「%@」"
+ }
+ }
+ }
+ },
"Peel couldn’t save the app folders." : {
"localizations" : {
"cs" : {
@@ -164711,6 +165135,112 @@
}
}
},
+ "Started the list of orphaned files that belong to an app over." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Seznam osiřelých souborů, které patří aplikaci, byl začat znovu."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Die Liste der verwaisten Dateien, die zu einer App gehören, wurde neu begonnen."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Se ha vuelto a empezar la lista de archivos huérfanos que pertenecen a una app."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "La liste des fichiers orphelins appartenant à une app a été recommencée."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ricominciato da capo l’elenco dei file orfani che appartengono a un’app."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "アプリに属する孤立ファイルのリストを最初からやり直しました。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "앱의 소유로 지정한 주인 없는 파일 목록을 처음부터 다시 시작했습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Opnieuw begonnen met de lijst van verweesde bestanden die bij een app horen."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zaczęto od nowa listę osieroconych plików należących do aplikacji."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Lista de arquivos órfãos que pertencem a um app recomeçada."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Lista fișierelor orfane care aparțin unei aplicații a fost reîncepută."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Список осиротевших файлов, принадлежащих приложению, начат заново."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Började om listan över övergivna filer som hör till en app."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bir uygulamaya ait sahipsiz dosyalar listesi baştan başlatıldı."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Список покинутих файлів, що належать програмі, почато наново."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "已重新开始建立属于某个App的孤立文件列表。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "已重新開始屬於某個App的孤立檔案列表。"
+ }
+ }
+ }
+ },
"Started the record of who signs your apps over." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
index 38d0dee3..ab0cb651 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
@@ -102,12 +102,13 @@ struct OrphansCommand: AsyncParsableCommand {
let running = Set(await RunningCopies.current.compactMap(\.bundleIdentifier))
let exclusions = await UnreadableExclusions.load()
let scanner = OrphanScanner(exclusions: exclusions)
+ let owners = OrphanOwners().load()
let scan = await ProgressLine.counting {
await scanner.scan(
installedApps: apps,
remembered: remembered,
running: running,
- owners: OrphanOwners().load(),
+ owners: owners ?? [:],
leftForAnAdministrator: await LeftForAnAdministrator().load()
)
}
@@ -136,15 +137,19 @@ struct OrphansCommand: AsyncParsableCommand {
Output.table(Self.administratorRows(for: scan), indent: " ")
}
}
- for note in Self.notes(for: scan) {
+ for note in Self.notes(for: scan, ownersUnreadable: owners == nil) {
Output.note(note)
}
}
- /// What the list could not cover, the folders Peel could not read and the places with more folders inside than
- /// Peel looks into, and how to remove what only an administrator can move.
- static func notes(for scan: OrphanScan) -> [String] {
+ /// What the list could not cover, the groups the person said belong to an app when that list can't be read, the
+ /// folders Peel could not read and the places with more folders inside than Peel looks into, and how to remove
+ /// what only an administrator can move.
+ static func notes(for scan: OrphanScan, ownersUnreadable: Bool) -> [String] {
var notes: [String] = []
+ if ownersUnreadable {
+ notes.append("Peel can't read the list of orphaned files you said belong to an app, so it lists them too. Start the list over in Peel's Settings > Exclusions.")
+ }
if !scan.unreadableLocations.isEmpty {
let folders = scan.unreadableLocations.map(\.url)
notes.append(Output.unreadableNote(for: folders, needsFullDiskAccess: scan.needsFullDiskAccess))
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanOwners.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanOwners.swift
index feb775ee..6444830b 100644
--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanOwners.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanOwners.swift
@@ -1,4 +1,5 @@
public import Foundation
+internal import PeelPrivileged
/// The orphaned files the person said belong to an installed app, by the identifier of their group, so Orphaned
/// Files stops listing them while that app is installed. It only ever takes rows out of the list: nothing is moved.
@@ -13,10 +14,21 @@ public struct OrphanOwners: Sendable {
PeelFolder.url.appending(path: "orphan-owners.json")
}
- /// Each group's identifier, lowercased, and the bundle identifier of the app it belongs to. A file that cannot be
- /// read gives none, which only lists those groups again.
- public func load() -> [String: String] {
- FileLock.whileHeld(beside: url) { read() ?? [:] }
+ /// Each group's identifier, lowercased, and the bundle identifier of the app it belongs to: none while the file
+ /// isn't there, and nil when it is there and can't be read, which lists those groups again.
+ public func load() -> [String: String]? {
+ // Taking the lock makes its file and folder, and a read must leave a home as it found it.
+ guard !url.isMissing else { return [:] }
+ return FileLock.whileHeld(beside: url) { read() }
+ }
+
+ /// Sets a list that cannot be read aside, under another name, so the person can say again what belongs to what.
+ @discardableResult
+ public func startOver() -> StartOver {
+ FileLock.whileHeld(beside: url) {
+ guard !url.isMissing, read() == nil else { return .notNeeded }
+ return DamagedFile.setAside(url) == nil ? .couldNotSetAside : .started
+ }
}
/// Records that `group` belongs to the app `bundleIdentifier`. False when the choice could not be saved, or when
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
index a20b390f..3744c16f 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
@@ -605,7 +605,10 @@ struct FileCommandTests {
["10 bytes", Output.path(left.url), "found for Left, bundle identifier"],
["10 bytes", Output.path(hinted.url), "found for Synth, developer, review: possible match"],
])
- #expect(OrphansCommand.notes(for: scan) == [OrphansCommand.byHand])
+ #expect(OrphansCommand.notes(for: scan, ownersUnreadable: false) == [OrphansCommand.byHand])
+ #expect(OrphansCommand.notes(for: scan, ownersUnreadable: true).first?.hasPrefix(
+ "Peel can't read the list of orphaned files you said belong to an app, so it lists them too."
+ ) == true)
let json = try Output.jsonText(OrphansCommand.report(for: scan))
let report = try #require(JSONSerialization.jsonObject(with: Data(json.utf8)) as? [String: Any])
let listed = try #require(report["forAnAdministrator"] as? [[String: Any]])
@@ -623,7 +626,7 @@ struct FileCommandTests {
var scan = OrphanScan(groups: [], unreadableLocations: [caches], needsFullDiskAccess: true)
scan.cutShortLocations = [caches]
- let notes = OrphansCommand.notes(for: scan)
+ let notes = OrphansCommand.notes(for: scan, ownersUnreadable: false)
#expect(notes == [
"Peel couldn't look inside /Users/me/Library/Caches, so something may be there that isn't listed. Give your terminal app Full Disk Access in System Settings to read the folders macOS protects.",
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
index c21ed786..96326165 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
@@ -777,6 +777,23 @@ struct OrphanScannerTests {
#expect(owners.load() == ["org.example.other": "com.microsoft.Word"])
}
+ @Test func aListOfOwnersIsReadWithoutWritingAndADamagedOneIsStartedOver() throws {
+ let directory = try TemporaryDirectory()
+ let folder = directory.url.appending(path: "Peel", directoryHint: .isDirectory)
+ let owners = OrphanOwners(url: folder.appending(path: "orphan-owners.json"))
+
+ #expect(owners.load() == [:])
+ #expect(folder.isMissing, "a read made Peel's folder")
+
+ try directory.file("Peel/orphan-owners.json", bytes: 16)
+ #expect(owners.load() == nil, "a list that can't be read read as no choices")
+ #expect(!owners.give("org.example.helper", to: "com.installed.app"))
+ #expect(owners.startOver() == .started)
+ #expect(owners.load() == [:])
+ #expect(owners.startOver() == .notNeeded)
+ #expect(owners.give("org.example.helper", to: "com.installed.app"))
+ }
+
/// An app installed since the scan owns what the list still calls orphaned.
@Test func whatAnAppInstalledSinceClaimsIsNoLongerOrphaned() async throws {
let directory = try TemporaryDirectory()
diff --git a/Peel/Model/OrphanLibrary.swift b/Peel/Model/OrphanLibrary.swift
index c63c6b98..046f1708 100644
--- a/Peel/Model/OrphanLibrary.swift
+++ b/Peel/Model/OrphanLibrary.swift
@@ -21,7 +21,8 @@ final class OrphanLibrary {
/// The apps list the scan was checked against. The page scans again when the list changes.
private(set) var scannedAgainst: AppLibrary.Listing?
- /// The groups the person said belong to an app, by identifier, with that app's bundle identifier.
+ /// The groups the person said belong to an app, by identifier, with that app's bundle identifier, or nil when that
+ /// list can't be read.
private(set) var owners = OrphanOwners().load()
var selectedGroup: OrphanGroup? {
@@ -77,7 +78,7 @@ final class OrphanLibrary {
installedApps: installedApps,
remembered: remembered,
running: running,
- owners: owners,
+ owners: owners ?? [:],
leftForAnAdministrator: await LeftForAnAdministrator().load()
)
if !scan.appsOnOtherDisks.isEmpty {
@@ -95,20 +96,33 @@ final class OrphanLibrary {
}
/// Takes `group` out of the list, as the person said it belongs to `app`. Nothing moves, and the group stays
- /// listed when the choice could not be saved.
- func give(_ group: OrphanGroup, to app: InstalledApp) {
- guard let identifier = app.bundleIdentifier, OrphanOwners().give(group.identifier, to: identifier), let scan
- else { return }
- owners[group.identifier.lowercased()] = identifier
- self.scan = scan.without(group.id)
+ /// listed when the choice could not be saved, which answers false.
+ func give(_ group: OrphanGroup, to app: InstalledApp) -> Bool {
+ let saved = app.bundleIdentifier.map { OrphanOwners().give(group.identifier, to: $0) } ?? false
+ owners = OrphanOwners().load()
+ guard saved else { return false }
+ if let scan {
+ self.scan = scan.without(group.id)
+ }
selectedURLs.subtract(group.items.map(\.url))
if selection == .group(group.id) { selection = nil }
+ return true
}
- /// Lists `groups` again, forgetting the app each was given to.
- func forget(_ groups: [String], from library: AppLibrary) async {
- guard OrphanOwners().take(groups) else { return }
+ /// Lists `groups` again, forgetting the app each was given to. False when that could not be saved.
+ func forget(_ groups: [String], from library: AppLibrary) async -> Bool {
+ guard OrphanOwners().take(groups) else {
+ owners = OrphanOwners().load()
+ return false
+ }
await refresh(from: library)
+ return true
+ }
+
+ func startOwnersOver() -> StartOver {
+ let answer = OrphanOwners().startOver()
+ owners = OrphanOwners().load()
+ return answer
}
}
diff --git a/Peel/Views/Orphans/OrphanList.swift b/Peel/Views/Orphans/OrphanList.swift
index 06a8377d..da8c7eac 100644
--- a/Peel/Views/Orphans/OrphanList.swift
+++ b/Peel/Views/Orphans/OrphanList.swift
@@ -5,8 +5,10 @@ struct OrphanList: View {
@Environment(AppLibrary.self) private var library
@Environment(OrphanLibrary.self) private var orphans
@Environment(HelperModel.self) private var helper
+ @Environment(\.openSettings) private var openSettings
@State private var searchText = ""
@State private var isRescanning = false
+ @State private var notGivenTo: String?
var body: some View {
@Bindable var orphans = orphans
@@ -32,7 +34,9 @@ struct OrphanList: View {
let apps = library.apps.filter { $0.bundleIdentifier != nil }
.sorted { $0.name.localizedStandardCompare($1.name) == .orderedAscending }
ForEach(apps) { app in
- Button(app.name) { orphans.give(group, to: app) }
+ Button(app.name) {
+ if !orphans.give(group, to: app) { notGivenTo = app.name }
+ }
}
}
}
@@ -146,6 +150,19 @@ struct OrphanList: View {
}
.rescanOnExclusionChange("OrphanList") { await orphans.refresh(from: library) }
.rescanAfterPutBack(.orphans) { await orphans.refresh(from: library) }
+ .alert(
+ "Peel couldn’t save that these files belong to \(notGivenTo ?? "")",
+ isPresented: Binding(get: { notGivenTo != nil }, set: { if !$0 { notGivenTo = nil } })
+ ) {
+ if orphans.owners == nil {
+ Button("Open Peel Settings") { SettingsPane.exclusions.open(with: openSettings) }
+ }
+ Button("OK", role: .cancel) {}
+ } message: {
+ orphans.owners == nil
+ ? Text("Peel can’t read its list of the orphaned files you said belong to an app, so it lists them all. Start the list over in Settings > Exclusions.")
+ : Text("Nothing changed. Check that Peel can write to its folder in Application Support, then try again.")
+ }
}
private func phase(_ filtered: [OrphanGroup], _ forAnAdministrator: [AdministratorItem]) -> ScanPhase {
diff --git a/Peel/Views/Settings/ExclusionsSettingsView.swift b/Peel/Views/Settings/ExclusionsSettingsView.swift
index 4fdcfed3..57fe7fb9 100644
--- a/Peel/Views/Settings/ExclusionsSettingsView.swift
+++ b/Peel/Views/Settings/ExclusionsSettingsView.swift
@@ -11,6 +11,7 @@ struct ExclusionsSettingsView: View {
@State private var selectedPaths: Set<URL> = []
@State private var selectedApps: Set<String> = []
@State private var selectedGroups: Set<String> = []
+ @State private var couldNotForget = false
private var paths: [URL] {
exclusions.exclusions.paths.sorted { $0.path(percentEncoded: false) < $1.path(percentEncoded: false) }
@@ -167,37 +168,52 @@ struct ExclusionsSettingsView: View {
}
Section {
- let groups = orphans.owners.keys.sorted()
- if groups.isEmpty {
- Text("No orphaned files are said to belong to an app.")
- .foregroundStyle(.secondary)
- } else {
- List(selection: $selectedGroups) {
- ForEach(groups, id: \.self) { group in
- HStack(spacing: 8) {
- Text(verbatim: group)
- .lineLimit(1)
- .truncationMode(.middle)
- if let owner = orphans.owners[group] {
- Text(verbatim: library.apps.first { $0.bundleIdentifier == owner }?.name ?? owner)
- .font(.caption)
- .foregroundStyle(.secondary)
+ if let owners = orphans.owners {
+ let groups = owners.keys.sorted()
+ if groups.isEmpty {
+ Text("No orphaned files are said to belong to an app.")
+ .foregroundStyle(.secondary)
+ } else {
+ List(selection: $selectedGroups) {
+ ForEach(groups, id: \.self) { group in
+ HStack(spacing: 8) {
+ Text(verbatim: group)
.lineLimit(1)
+ .truncationMode(.middle)
+ if let owner = owners[group] {
+ let name = library.apps.first { $0.bundleIdentifier == owner }?.name
+ Text(verbatim: name ?? owner)
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ .lineLimit(1)
+ }
}
+ .tag(group)
}
- .tag(group)
+ }
+ .frame(height: settingsListHeight(rows: groups.count))
+ .scrollContentBackground(.hidden)
+ .onDeleteCommand { forgetSelectedGroups() }
+ }
+ HStack {
+ Spacer()
+ Button("Remove", systemImage: "minus") { forgetSelectedGroups() }
+ .disabled(selectedGroups.isEmpty)
+ }
+ .editingControls()
+ } else {
+ Text("Peel can’t read this list, so Orphaned Files lists these files again. Starting over keeps the old list beside a new one.")
+ .foregroundStyle(.secondary)
+ HStack {
+ Spacer()
+ StartOverButton(
+ file: OrphanOwners.defaultURL,
+ startedOver: "Started the list of orphaned files that belong to an app over."
+ ) {
+ orphans.startOwnersOver()
}
}
- .frame(height: settingsListHeight(rows: groups.count))
- .scrollContentBackground(.hidden)
- .onDeleteCommand { forgetSelectedGroups() }
- }
- HStack {
- Spacer()
- Button("Remove", systemImage: "minus") { forgetSelectedGroups() }
- .disabled(selectedGroups.isEmpty)
}
- .editingControls()
} header: {
heading("Orphaned Files That Belong to an App", "Orphaned Files doesn’t list these while the app you said they belong to is installed. Nothing of them was moved. Remove one to list it again.")
}
@@ -219,6 +235,13 @@ struct ExclusionsSettingsView: View {
guard !keeping.isEmpty else { return }
Task { await exclusions.add(paths: keeping) }
}
+ .alert("Peel couldn’t list these files again", isPresented: $couldNotForget) {
+ Button("OK", role: .cancel) {}
+ } message: {
+ orphans.owners == nil
+ ? Text("Peel can’t read its list of the orphaned files you said belong to an app, so it lists them all. Start the list over in Settings > Exclusions.")
+ : Text("Nothing changed. Check that Peel can write to its folder in Application Support, then try again.")
+ }
.alert(refused.count == 1 ? "That folder can’t be excluded." : "These folders can’t be excluded.", isPresented: isShowingRefusal) {
Button("OK", role: .cancel) {}
} message: {
@@ -234,6 +257,6 @@ extension ExclusionsSettingsView {
private func forgetSelectedGroups() {
let forgotten = Array(selectedGroups)
selectedGroups = []
- Task { await orphans.forget(forgotten, from: library) }
+ Task { couldNotForget = await !orphans.forget(forgotten, from: library) }
}
}