Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Remove Downloads leaves alone what was excluded since the scan
Țugui Dragoșe3b9d2e92ebe
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/CloudStorage.swift b/Packages/PeelCore/Sources/PeelCore/Space/CloudStorage.swiftindex 44c5e5d6..7eb1b7ae 100644--- a/Packages/PeelCore/Sources/PeelCore/Space/CloudStorage.swift+++ b/Packages/PeelCore/Sources/PeelCore/Space/CloudStorage.swift@@ -32,6 +32,9 @@ public struct CloudRefusal: Sendable, Hashable, Identifiable {public enum Reason: Sendable, Hashable {/// The file is not as it was at the scan: edited, moved, or freed already, or not safely in iCloud.case changedSinceScan+ /// Excluded in Settings since the scan, or the exclusions are not known, so it is left as a move to the+ /// Trash would be.+ case excluded/// macOS refused to free the file. The value is the error message it gave.case failed(String)}@@ -204,13 +207,17 @@ public enum CloudStorage {}/// Frees the local copies of `files` and returns the ones that were not freed. Each file is checked again- /// first: the list may have been on screen for hours, and a file edited since then may exist in its newest- /// form only on the local disk.+ /// first, against `exclusions` as they are now as well: the list may have been on screen for hours, and a file+ /// edited since then may exist in its newest form only on the local disk.@discardableResult@concurrent- public static func free(_ files: [CloudFile]) async -> [CloudRefusal] {+ public static func free(_ files: [CloudFile], exclusions: Exclusions) async -> [CloudRefusal] {var refused: [CloudRefusal] = []for file in files {+ guard exclusions.isKnown, !exclusions.excludes(file.url) else {+ refused.append(CloudRefusal(url: file.url, reason: .excluded))+ continue+ }var url = file.urlurl.removeAllCachedResourceValues()guarddiff --git a/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swiftindex 971ad446..8597f8aa 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swift@@ -34,13 +34,26 @@ struct CloudStorageTests {let url = try directory.file("file.bin", bytes: 2_000_000)let scanned = CloudFile(url: url, name: "file.bin", container: "iCloud Drive", size: 2_000_000, modified: .distantPast)- let refused = await CloudStorage.free([scanned])+ let refused = await CloudStorage.free([scanned], exclusions: .none)#expect(refused.map(\.url) == [url])#expect(refused.first?.reason == .changedSinceScan)#expect(FileManager.default.fileExists(atPath: url.path(percentEncoded: false)))}+ /// The list on screen was filtered by the exclusions as they stood at the scan, so a file excluded since, or+ /// any file while the exclusions are not known, stays downloaded.+ @Test func leavesAloneWhatWasExcludedSinceTheScan() async throws {+ let directory = try TemporaryDirectory()+ let url = try directory.file("Offline/file.bin", bytes: 2_000_000)+ let scanned = CloudFile(url: url, name: "file.bin", container: "iCloud Drive", size: 2_000_000, modified: .distantPast)+ let offline = Exclusions(paths: [directory.url.appending(path: "Offline", directoryHint: .isDirectory)])++ #expect(await CloudStorage.free([scanned], exclusions: offline).map(\.reason) == [.excluded])+ #expect(await CloudStorage.free([scanned], exclusions: .notYetRead).map(\.reason) == [.excluded])+ #expect(await CloudStorage.free([scanned], exclusions: .unreadable).map(\.reason) == [.excluded])+ }+@Test func callsEachFolderWhatTheUserCallsIt() {let root = URL(filePath: "/Users/x/Library/Mobile Documents", directoryHint: .isDirectory)func name(_ path: String) -> String {diff --git a/Peel/Model/CloudLibrary.swift b/Peel/Model/CloudLibrary.swiftindex 3ebe3147..5b4bc139 100644--- a/Peel/Model/CloudLibrary.swift+++ b/Peel/Model/CloudLibrary.swift@@ -39,7 +39,7 @@ final class CloudLibrary {isFreeing = truedefer { isFreeing = false }let chosen = files?.filter { selectedURLs.contains($0.url) } ?? []- let refused = await CloudStorage.free(chosen)+ let refused = await CloudStorage.free(chosen, exclusions: ExclusionsStore.shared.exclusions)let kept = Set(refused.map(\.url))await refresh()refusals = refuseddiff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swiftindex 16b76bfa..03d675f4 100644--- a/Peel/Views/Presentation.swift+++ b/Peel/Views/Presentation.swift@@ -164,6 +164,7 @@ extension CloudRefusal {var explanation: String {switch reason {case .changedSinceScan: String(localized: "It isn’t as it was when Peel looked at it: it may have been edited, stopped syncing, or been freed already, so Peel left it alone.")+ case .excluded: String(localized: "Excluded in Settings")case .failed(let message): message}}