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.

Show the cloud only for a copy that syncs through one

Țugui Dragoș3dcac09a5dc5
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index ba63af8c..ff43690d 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -172047,11 +172047,12 @@
}
},
"Stays" : {
+ "comment" : "The badge on a copy in Duplicates that Peel never moves: it stays where it is, because it syncs to the person's other devices or has Finder tags, a Finder comment, or a resource fork the other copies lack. Say that it stays, not that it syncs, and keep it apart from Keep, the badge of the copy Peel suggests keeping.",
"localizations" : {
"cs" : {
"stringUnit" : {
"state" : "translated",
- "value" : "Synchronizuje se"
+ "value" : "Zůstává"
}
},
"de" : {
@@ -172063,7 +172064,7 @@
"es" : {
"stringUnit" : {
"state" : "translated",
- "value" : "Se sincroniza"
+ "value" : "Se queda"
}
},
"fr" : {
@@ -172081,7 +172082,7 @@
"ja" : {
"stringUnit" : {
"state" : "translated",
- "value" : "同期済み"
+ "value" : "移動しない"
}
},
"ko" : {
@@ -172093,61 +172094,61 @@
"nl" : {
"stringUnit" : {
"state" : "translated",
- "value" : "Gesynchroniseerd"
+ "value" : "Blijft staan"
}
},
"pl" : {
"stringUnit" : {
"state" : "translated",
- "value" : "Synchronizowane"
+ "value" : "Zawsze zostaje"
}
},
"pt" : {
"stringUnit" : {
"state" : "translated",
- "value" : "Sincronizada"
+ "value" : "Permanece"
}
},
"ro" : {
"stringUnit" : {
"state" : "translated",
- "value" : "Se sincronizează"
+ "value" : "Rămâne pe loc"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
- "value" : "Синхронизируется"
+ "value" : "Остается"
}
},
"sv" : {
"stringUnit" : {
"state" : "translated",
- "value" : "Synkroniseras"
+ "value" : "Stannar kvar"
}
},
"tr" : {
"stringUnit" : {
"state" : "translated",
- "value" : "Eşzamanlanıyor"
+ "value" : "Kalıyor"
}
},
"uk" : {
"stringUnit" : {
"state" : "translated",
- "value" : "Синхронізується"
+ "value" : "Лишається на місці"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
- "value" : "已同步"
+ "value" : "保持原位"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
- "value" : "已同步"
+ "value" : "留在原處"
}
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift
index adb08221..1aefe036 100644
--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift
@@ -432,7 +432,9 @@ public struct DuplicateFinder: Sendable {
reclaimableSize: ReclaimableSpace.of(candidate.url),
allocatedSize: ReclaimableSpace.allocated(candidate.url),
identity: candidate.identity,
- heldBack: candidate.heldBack
+ heldBack: candidate.heldBack,
+ syncsThroughACloud: candidate.heldBack == .inTheCloud
+ && (candidate.url.isInTheCloud || Self.isInACloudFolder(Self.path(of: candidate.url)))
)
}
let group = DuplicateGroup(id: members[0].digest.hexadecimal, files: files)
diff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift
index a15c516c..a8757be1 100644
--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift
@@ -42,6 +42,9 @@ public struct DuplicateFile: Sendable, Hashable, Identifiable {
/// Why the copy is listed but never moved: it syncs to the person's other devices, where a move to the Trash
/// would remove it too. Nil for a copy that may move.
public var heldBack: HoldBack? = nil
+ /// True for a copy that syncs through iCloud Drive or a cloud's File Provider, rather than through an app that
+ /// keeps folders in step between devices, such as Syncthing.
+ public var syncsThroughACloud = false
public var id: URL { url }
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift
index 028c2164..c71b1ea0 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift
@@ -357,6 +357,30 @@ struct DuplicateFinderTests {
#expect(inside.groups.isEmpty, "a folder inside a repository was scanned")
}
+ /// A copy in iCloud Drive or a cloud's File Provider folder syncs through that cloud, and one a sync app keeps in
+ /// step, such as Syncthing, through that app: the row's symbol says which.
+ @Test func tellsACloudFromASyncApp() async throws {
+ let directory = try TemporaryDirectory()
+ let contents = randomData(count: 3_000)
+ try directory.directory("home/Synced/.stfolder")
+ try directory.file("home/Synced/a.bin", contents: contents)
+ try directory.file("home/Library/CloudStorage/Provider/a.bin", contents: contents)
+ try directory.file("home/Documents/a.bin", contents: contents)
+
+ let folders = ["home/Synced", "home/Library/CloudStorage/Provider", "home/Documents"]
+ let scan = try await scan(directory, folders: folders)
+
+ let group = try #require(scan.groups.first)
+ let copies = Dictionary(
+ uniqueKeysWithValues: group.files.map { ($0.url.deletingLastPathComponent().lastPathComponent, $0) }
+ )
+ #expect(copies["Synced"]?.heldBack == .inTheCloud)
+ #expect(copies["Synced"]?.syncsThroughACloud == false)
+ #expect(copies["Provider"]?.heldBack == .inTheCloud)
+ #expect(copies["Provider"]?.syncsThroughACloud == true)
+ #expect(copies["Documents"]?.syncsThroughACloud == false)
+ }
+
@Test func countsOnlyTheGroupsWithSomethingToMove() async throws {
let directory = try TemporaryDirectory()
let synced = randomData(count: 3_000)
diff --git a/Peel/Views/Duplicates/DuplicateGroupView.swift b/Peel/Views/Duplicates/DuplicateGroupView.swift
index 75f67bba..8f51dd5d 100644
--- a/Peel/Views/Duplicates/DuplicateGroupView.swift
+++ b/Peel/Views/Duplicates/DuplicateGroupView.swift
@@ -129,10 +129,10 @@ private struct DuplicateFileRow: View {
HStack(alignment: .firstTextBaseline, spacing: 10) {
if let heldBack = file.heldBack {
// No checkbox: the copy can never be selected, and a disabled one would dim the very words the
- // person reads here, where the copy is. The cloud, or the tag, stands where the other rows' checkbox
- // stands, 16 points wide and 5 before the item, so the copies of a group line up.
+ // person reads here, where the copy is. The mark of why it stays stands where the other rows'
+ // checkbox stands, 16 points wide and 5 before the item, so the copies of a group line up.
HStack(alignment: .firstTextBaseline, spacing: 5) {
- Image(systemName: heldBack == .inTheCloud ? "icloud" : "tag")
+ Image(systemName: heldBack != .inTheCloud ? "tag" : file.syncSymbol)
.foregroundStyle(heldBack == .inTheCloud ? AnyShapeStyle(.blue) : AnyShapeStyle(.secondary))
.frame(width: 16, height: 16)
.alignmentGuide(.firstTextBaseline) { $0[.bottom] - 3 }
@@ -227,3 +227,15 @@ struct DuplicateSelectedTotal: View {
.accessibilityLabel(Text("\(bytes.byteCount) can be freed"))
}
}
+
+extension DuplicateFile {
+ var syncSymbol: String {
+ Self.syncSymbol(throughACloud: syncsThroughACloud)
+ }
+
+ /// The cloud for copies that sync through iCloud Drive or a cloud's File Provider, and arrows for those an app
+ /// keeps in step, such as Syncthing, which go through no cloud.
+ static func syncSymbol(throughACloud: Bool) -> String {
+ throughACloud ? "icloud" : "arrow.triangle.2.circlepath"
+ }
+}
diff --git a/Peel/Views/Duplicates/DuplicateList.swift b/Peel/Views/Duplicates/DuplicateList.swift
index 10db289a..7ae1d4d0 100644
--- a/Peel/Views/Duplicates/DuplicateList.swift
+++ b/Peel/Views/Duplicates/DuplicateList.swift
@@ -293,11 +293,12 @@ private struct DuplicateGroupRow: View {
Spacer(minLength: 6)
if group.everyCopySyncs {
// Nothing here frees space on this Mac: the figure is the copies' size, with the symbol that says
- // they sync.
+ // they sync, the cloud only when every copy syncs through one.
Label {
Text(group.size.byteCount)
} icon: {
- Image(systemName: "icloud")
+ let throughACloud = group.files.allSatisfy(\.syncsThroughACloud)
+ Image(systemName: DuplicateFile.syncSymbol(throughACloud: throughACloud))
}
.rowFigure()
} else {