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.

Compare nothing in Duplicates while the exclusions can't be read

Țugui Dragoș91652719dad2
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index c29d8c79..20a4f04b 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -114228,6 +114228,112 @@
}
}
},
+ "Peel compares nothing until you start the list over in Settings, since it would read what you asked it to leave alone." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dokud v Nastavení nezačnete seznam znovu, Peel nic neporovná, protože by četl to, co jste mu řekli, aby nechal nedotčené."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel vergleicht nichts, bis du die Liste in den Einstellungen neu beginnst, da Peel sonst lesen würde, was es auf deinen Wunsch unangetastet lassen soll."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no compara nada hasta que vuelvas a empezar la lista en Ajustes, ya que leería lo que le has pedido que no toque."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel ne compare rien tant que vous n’avez pas recommencé la liste dans les Réglages, car il lirait ce à quoi vous lui avez demandé de ne pas toucher."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non confronta nulla finché non ricominci l’elenco da capo nelle Impostazioni, perché leggerebbe ciò che gli hai chiesto di non toccare."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "“設定”でリストを最初からやり直すまで、Peelは何も比較しません。比較すると、手を付けないよう指定されたものまで読み取ってしまうためです。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "설정에서 목록을 처음부터 다시 시작하기 전까지 Peel은 아무것도 비교하지 않습니다. 비교하면 그대로 두라고 요청한 항목을 읽게 되기 때문입니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel vergelijkt niets totdat je in Instellingen opnieuw begint met de lijst, omdat Peel anders zou lezen wat je Peel hebt gevraagd met rust te laten."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel niczego nie porównuje, dopóki nie zaczniesz listy od nowa w Ustawieniach, ponieważ odczytałby to, co według Ciebie ma zostawić w spokoju."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não compara nada até você recomeçar a lista nos Ajustes, já que leria aquilo em que você pediu para ele não mexer."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu compară nimic până când nu reîncepeți lista în Configurări, deoarece ar citi ce i‑ați cerut să lase neatins."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel ничего не сравнивает, пока Вы не начнете список заново в Настройках, поскольку иначе он прочитал бы то, что Вы просили не трогать."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel jämför ingenting förrän du börjar om listan i Inställningar, eftersom Peel annars skulle läsa det som du har bett den att lämna orört."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Siz listeyi Ayarlar’da baştan başlatana kadar Peel hiçbir şeyi karşılaştırmaz, çünkü aksi hâlde dokunmamasını istediğiniz şeyleri okurdu."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel нічого не порівнює, доки ви не почнете список наново в Параметрах, бо інакше прочитала б те, що ви просили не чіпати."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "在你于“设置”中重新开始建立列表之前,Peel不会比较任何内容,因为否则它会读取你要求它不去触碰的内容。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "在你於「設定」中重新開始此列表之前,Peel不會比對任何項目,否則它會讀取你要求它不要動的項目。"
+ }
+ }
+ }
+ },
"Peel couldn’t confirm it is still nobody’s: an installed app may claim it now. Scan again to review it." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
index 399f7117..bf30747c 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
@@ -732,8 +732,16 @@ 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.")
+ }
+
func run() async throws {
- let exclusions = await UnreadableExclusions.load()
+ let store = ExclusionStore()
+ let exclusions = await store.load()
+ if let refusal = Self.refusal(for: exclusions, savedAt: store.url) { throw refusal }
let finder = DuplicateFinder(exclusions: exclusions, digestMemory: DigestMemory())
let urls = folders.isEmpty ? finder.defaultFolders : folders.map(URL.init(argument:))
let scan = try await ProgressLine.reporting { show in
diff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift
index e34d9ca1..6f2c3b2f 100644
--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift
@@ -124,6 +124,10 @@ public struct DuplicateFinder: Sendable {
_ options: DuplicateScanOptions,
progress: @escaping @Sendable (DuplicateScanProgress) -> Void = { _ in }
) async throws(CancellationError) -> DuplicateScan {
+ // Nothing is read before the exclusions are known, or what the person excluded would be read with the rest.
+ guard exclusions.isKnown else {
+ return DuplicateScan(groups: [], unreadableLocations: [], exclusionsNotKnown: true)
+ }
let environment = SearchEnvironment(homeDirectory: homeDirectory, rootDirectory: URL(filePath: "/"))
let removalGuard = RemovalGuard(environment: environment, exclusions: exclusions)
let skipped = options.folders.compactMap { folder in
diff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift
index 96a536fb..cb3f5a48 100644
--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift
@@ -134,6 +134,8 @@ public struct DuplicateScan: Sendable {
/// True when macOS privacy protection refused one of the unreadable folders, which Full Disk Access would
/// allow. It stays false for a folder locked by ordinary permissions, or one that is missing.
public var needsFullDiskAccess = false
+ /// True when the exclusions couldn't be read, so the scan compared nothing.
+ public var exclusionsNotKnown = false
/// A chosen folder the scan did not look in, and why.
public struct FolderSetAside: Sendable, Hashable {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DigestMemoryTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DigestMemoryTests.swift
index bf35b810..70b7b0e1 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DigestMemoryTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DigestMemoryTests.swift
@@ -79,6 +79,22 @@ struct DigestMemoryTests {
#expect(memory.load().sample(of: try #require(FileIdentity.of(first))) == nil, "a file was read")
}
+ @Test func comparesNoFoldersWhileTheExclusionsCantBeRead() async throws {
+ let directory = try TemporaryDirectory()
+ let memory = DigestMemory(url: directory.url.appending(path: "digests.bin"))
+ let contents = randomData(count: FileDigest.sampleLength * 4)
+ let first = try directory.file("home/Documents/Taxes/2025.bin", contents: contents)
+ try directory.file("home/Documents/Taxes copy/2025.bin", contents: contents)
+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)
+
+ let result = try await DuplicateFinder(homeDirectory: home, exclusions: .unreadable, digestMemory: memory)
+ .scan(.everySize(in: [home]))
+
+ #expect(result.exclusionsNotKnown)
+ #expect(result.groups.isEmpty && result.folderGroups.isEmpty)
+ #expect(memory.load().sample(of: try #require(FileIdentity.of(first))) == nil, "a file was read")
+ }
+
@Test func aScanRemembersWhatItRead() async throws {
let directory = try TemporaryDirectory()
let memory = DigestMemory(url: directory.url.appending(path: "digests.bin"))
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
index a0801d92..a20b390f 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
@@ -659,6 +659,17 @@ struct FileCommandTests {
#expect(notes.contains { $0.hasPrefix("Peel didn't look in /Users/me/Projects/app, so there may be duplicates there.") })
}
+ @Test func duplicatesComparesNothingWhileTheExclusionsCantBeRead() {
+ let saved = URL(filePath: "/Users/me/Library/Application Support/Peel/exclusions.json")
+
+ let refusal = DuplicatesCommand.refusal(for: .unreadable, savedAt: saved)
+
+ #expect(refusal?.description.hasPrefix(
+ "Peel couldn't read your exclusions at /Users/me/Library/Application Support/Peel/exclusions.json, so it compares nothing"
+ ) == true)
+ #expect(DuplicatesCommand.refusal(for: .none, savedAt: saved) == nil)
+ }
+
/// `peel duplicates --json` names the folders it couldn't read and the chosen folders it didn't look in.
@Test func theDuplicatesReportSaysWhereItCouldNotLook() throws {
let scan = DuplicateScan(
diff --git a/Peel/Model/DuplicateLibrary.swift b/Peel/Model/DuplicateLibrary.swift
index f55baed0..0b122018 100644
--- a/Peel/Model/DuplicateLibrary.swift
+++ b/Peel/Model/DuplicateLibrary.swift
@@ -163,6 +163,11 @@ final class DuplicateLibrary {
var options = DuplicateScanOptions(folders: folders)
options.kind = kind
options.minimumSize = minimumSize
+ // Read at launch, so only a scan asked for in its first moments waits for them.
+ if !ExclusionsStore.shared.exclusions.isKnown, !ExclusionsStore.shared.exclusions.isUnreadable {
+ await ExclusionsStore.shared.load()
+ guard current == generation else { return }
+ }
let exclusions = ExclusionsStore.shared.exclusions
let (updates, continuation) = AsyncStream.makeStream(
diff --git a/Peel/Views/Duplicates/DuplicateList.swift b/Peel/Views/Duplicates/DuplicateList.swift
index 96a330ad..5f32688d 100644
--- a/Peel/Views/Duplicates/DuplicateList.swift
+++ b/Peel/Views/Duplicates/DuplicateList.swift
@@ -4,6 +4,7 @@ import SwiftUI
struct DuplicateList: View {
@Environment(DuplicateLibrary.self) private var duplicates
@Environment(ExclusionsStore.self) private var exclusions
+ @Environment(\.openSettings) private var openSettings
@State private var searchText = ""
@State private var isConfirmingNewScan = false
@State private var isShowingSettings = false
@@ -54,6 +55,14 @@ struct DuplicateList: View {
.overlay {
if !(scan.groups.isEmpty && scan.folderGroups.isEmpty), groups.isEmpty, folderGroups.isEmpty {
ContentUnavailableView.search(text: searchText)
+ } else if scan.exclusionsNotKnown {
+ ContentUnavailableView {
+ Label("Peel couldn’t read your exclusions", systemImage: "exclamationmark.triangle")
+ } description: {
+ Text("Peel compares nothing until you start the list over in Settings, since it would read what you asked it to leave alone.")
+ } actions: {
+ Button("Open Peel Settings") { SettingsPane.exclusions.open(with: openSettings) }
+ }
} else if scan.readNothing {
// Shown instead of "No Duplicates": copies may be in folders Peel couldn't read, which are
// named, or in the chosen folders it set aside, each named with why.
@@ -140,7 +149,8 @@ struct DuplicateList: View {
.announcesScan(
duplicates.isScanning,
found: summary,
- couldNotLook: duplicates.scan?.readNothing != true ? nil
+ couldNotLook: duplicates.scan?.exclusionsNotKnown == true ? "Peel couldn’t read your exclusions"
+ : duplicates.scan?.readNothing != true ? nil
: duplicates.scan?.unreadableLocations.isEmpty == true ? "Not Everything Could Be Searched"
: "Not Everything Could Be Read",
wasStopped: duplicates.scan == nil