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.

Count only the duplicate groups with something to move

Țugui Dragoș27a88d1a0e0b
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 6e8fa85b..9c9b337f 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -105327,6 +105327,112 @@
}
}
},
+ "Nothing to move: every other copy syncs to your other devices." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Není co přesunout: všechny další kopie se synchronizují s vašimi ostatními zařízeními."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nichts zu verschieben: Jede andere Kopie wird mit deinen anderen Geräten synchronisiert."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nada que trasladar: todas las demás copias se sincronizan con tus otros dispositivos."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Rien à déplacer : toutes les autres copies sont synchronisées avec vos autres appareils."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Niente da spostare: ogni altra copia si sincronizza con gli altri tuoi dispositivi."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "移動できるものはありません。残すコピー以外は、すべてほかのデバイスに同期されています。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "이동할 항목 없음: 나머지 복사본이 모두 다른 기기와 동기화됩니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Niets te verplaatsen: elke andere kopie wordt gesynchroniseerd met je andere apparaten."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie ma nic do przeniesienia: każda inna kopia jest synchronizowana z Twoimi pozostałymi urządzeniami."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nada para mover: todas as outras cópias são sincronizadas com os seus outros dispositivos."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nimic de mutat: fiecare copie în plus se sincronizează pe celelalte dispozitive ale dvs."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Нечего перемещать: все остальные копии синхронизируются с другими Вашими устройствами."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Inget att flytta: alla andra kopior synkroniseras till dina andra enheter."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Taşınacak bir şey yok: geri kalan her kopya diğer aygıtlarınızla eşzamanlanıyor."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Немає чого переміщувати: усі інші копії синхронізуються з іншими вашими пристроями."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "没有可移动的内容:其他每个副本都会同步到你的其他设备。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "沒有可移動的項目:其他每份副本都會與你的其他裝置同步。"
+ }
+ }
+ }
+ },
"Nothing turns this on or off: Shortcuts and Siri use it whenever someone asks for the app’s actions. Removing it means removing the app it came with." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift
index f180292f..c0ed788d 100644
--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift
@@ -181,6 +181,13 @@ public struct DuplicateScan: Sendable {
return Set(files + folders)
}
+ /// How many groups moving copies would free something in. A group of files counts only with two copies that may
+ /// move, since one always stays; a folder that syncs to other devices is never offered, so every group of
+ /// folders counts.
+ public var groupsWithSomethingToMove: Int {
+ groups.count { $0.movableFiles.count > 1 } + folderGroups.count
+ }
+
/// Returns `selection` limited to what this scan can still move: only files it lists, and never every copy of
/// a group, which the move refuses. When every copy left in a group is selected, its first copy is kept.
public func keepingOneOfEach(_ selection: Set<URL>) -> Set<URL> {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift
index 41e0f727..3e9580eb 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift
@@ -339,6 +339,22 @@ struct DuplicateFinderTests {
/// A folder that syncs to other devices is scanned, and each copy found in it is listed and held back: a copy
/// moved there would be removed from every device. Nothing in such a group is suggested, since the one copy that
/// could move is the only one that stays on this Mac.
+ @Test func countsOnlyTheGroupsWithSomethingToMove() async throws {
+ let directory = try TemporaryDirectory()
+ let synced = randomData(count: 3_000)
+ let local = randomData(count: 3_000)
+ try directory.directory("home/Synced/.stfolder")
+ try directory.file("home/Synced/a.bin", contents: synced)
+ try directory.file("home/Documents/a.bin", contents: synced)
+ try directory.file("home/Documents/b.bin", contents: local)
+ try directory.file("home/Documents/b copy.bin", contents: local)
+
+ let scan = try await scan(directory, folders: ["home/Synced", "home/Documents"])
+
+ #expect(scan.groups.count == 2)
+ #expect(scan.groupsWithSomethingToMove == 1)
+ }
+
@Test func listsACopyThatSyncsApartAndNeverSelectsIt() async throws {
let directory = try TemporaryDirectory()
let contents = randomData(count: 3_000)
diff --git a/Peel/Model/FoundLastTimeStore.swift b/Peel/Model/FoundLastTimeStore.swift
index 3754fae2..42afd75f 100644
--- a/Peel/Model/FoundLastTimeStore.swift
+++ b/Peel/Model/FoundLastTimeStore.swift
@@ -91,10 +91,7 @@ extension DuplicateLibrary {
var looked: Looked? {
scan.map { scan in
let reclaimable = (scan.groups.map(\.reclaimableSize) + scan.folderGroups.map(\.reclaimableSize)).cappedSum
- return Looked(
- count: scan.groups.count + scan.folderGroups.count,
- size: SizeTotal(known: reclaimable, isComplete: true)
- )
+ return Looked(count: scan.groupsWithSomethingToMove, size: SizeTotal(known: reclaimable, isComplete: true))
}
}
}
diff --git a/Peel/Views/Duplicates/DuplicateList.swift b/Peel/Views/Duplicates/DuplicateList.swift
index 6ecd24e4..2e0aba58 100644
--- a/Peel/Views/Duplicates/DuplicateList.swift
+++ b/Peel/Views/Duplicates/DuplicateList.swift
@@ -161,7 +161,10 @@ struct DuplicateList: View {
/// What VoiceOver hears when a scan ends: what it found, then the folders Peel couldn't read and the chosen
/// folders it set aside, each kind in its own words.
private var summary: AttributedString? {
- guard var words = duplicates.summary, let scan = duplicates.scan else { return duplicates.summary }
+ guard let scan = duplicates.scan else { return duplicates.summary }
+ let found = duplicates.summary ?? (scan.groups.isEmpty && scan.folderGroups.isEmpty
+ ? nil : AttributedString(localized: "Nothing to move: every other copy syncs to your other devices."))
+ guard var words = found else { return nil }
if !scan.unreadableLocations.isEmpty {
let count = scan.unreadableLocations.count
words = words + " " + AttributedString(localized: "Peel couldn’t look in ^[\(count) folder](inflect: true).")