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
A reset never offers a container folder that may hold what exists nowhere else
Țugui Dragoșe269dec4ccb6
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swift b/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swiftindex 7dafc9d9..ac27c61d 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swift@@ -17,8 +17,9 @@ public struct AppReset: Sendable {public let url: URLpublic let kind: SearchLocation.Kindpublic let group: Group- /// Nil when measuring timed out or was refused. An unknown size is not the same as zero.- public let size: Int64?+ /// Always known: a folder that was not measured or not read is never offered, nor one holding a wallet or a+ /// repository, as the uninstall holds such a folder back.+ public let size: Int64public var id: URL { url }}@@ -105,7 +106,7 @@ public struct AppReset: Sendable {exclusions: Exclusions = .none,environment: SearchEnvironment = .current) async -> AppReset {- await prepare(app, installedApps: installedApps, exclusions: exclusions, environment: environment, measure: FileSize.measure)+ await prepare(app, installedApps: installedApps, exclusions: exclusions, environment: environment, measure: LeftoverScanner.walk)}@concurrent@@ -114,7 +115,7 @@ public struct AppReset: Sendable {installedApps: [InstalledApp],exclusions: Exclusions,environment: SearchEnvironment,- measure: FileSize.Measure+ measure: LeftoverScanner.Measure) async -> AppReset {guard !exclusions.excludes(app) else {return AppReset(app: app, items: [], keepsAppData: false, needsFullDiskAccess: false)@@ -155,7 +156,7 @@ public struct AppReset: Sendable {return AppReset(app: app,- items: items.sorted { SizeTotal([$0.size]) > SizeTotal([$1.size]) },+ items: items.sorted { $0.size > $1.size },keepsAppData: keepsAppData,needsFullDiskAccess: needsFullDiskAccess)@@ -166,13 +167,17 @@ public struct AppReset: Sendable {of app: InstalledApp,exclusions: Exclusions,home: URL,- measure: FileSize.Measure+ measure: LeftoverScanner.Measure) async -> [Item] {var items: [Item] = []for folder in containerFolders {let url = container.appending(path: folder.path, directoryHint: .isDirectory)guard url.isRealFolder, !exclusions.excludes(url), !exclusions.holds(url), !holdsKeys(url, home: home) else { continue }- items.append(Item(url: url, kind: folder.kind, group: folder.group, size: await measure(url)))+ // What the uninstall would hold back is never offered: a wallet or a repository inside, or a folder that+ // was not measured or not read.+ let seen = await measure(url)+ guard let seen, HoldBack.seen(in: seen) == nil else { continue }+ items.append(Item(url: url, kind: folder.kind, group: folder.group, size: seen.size))}let preferences = container.appending(path: containerPreferenceFolder, directoryHint: .isDirectory)guard preferences.isRealFolder else { return items }@@ -182,7 +187,9 @@ public struct AppReset: Sendable {let contents = (try? FileManager.default.contentsOfDirectory(at: preferences, includingPropertiesForKeys: [.isSymbolicLinkKey])) ?? []for file in contents where names.contains(file.lastPathComponent.lowercased()) {guard (try? file.resourceValues(forKeys: [.isSymbolicLinkKey]).isSymbolicLink) != true, !exclusions.excludes(file) else { continue }- items.append(Item(url: file, kind: .preferences, group: .settings, size: await measure(file)))+ let seen = await measure(file)+ guard let seen, HoldBack.seen(in: seen) == nil else { continue }+ items.append(Item(url: file, kind: .preferences, group: .settings, size: seen.size))}return items}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swiftindex cf2655b3..47390fed 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swift@@ -215,20 +215,35 @@ struct AppResetTests {#expect(Set(reset.items.map(\.url.lastPathComponent)) == ["com.example.app.plist"])}- /// A sandboxed app's cache can be the biggest thing a reset clears. A folder that was not measured in time is- /// still offered, listed first, and the size of a selection that holds it is marked incomplete.- @Test func aFolderInAContainerThatDidNotAnswerInTimeIsNotReadAsEmpty() async throws {+ /// A reset clears what the app makes again and nothing that may exist nowhere else: a folder in a container that+ /// holds a wallet or a repository is never offered, as the uninstall holds such a folder back. The container is+ /// looked into because it is held back only for the documents in it.+ @Test func aFolderInAContainerHoldingAWalletOrARepositoryIsNotOffered() async throws {+ let directory = try TemporaryDirectory()+ let library = "Library/Containers/com.example.app/Data/Library"+ try directory.file("Library/Containers/com.example.app/Data/Documents/letter.txt", bytes: 4096)+ try directory.file("\(library)/Caches/coin/wallet.dat", bytes: 4096)+ try directory.file("\(library)/Logs/mirror/.git/HEAD", bytes: 4096)+ try directory.file("\(library)/WebKit/site", bytes: 4096)++ let reset = await AppReset.prepare(app(), installedApps: [app()], environment: home(directory))++ #expect(reset.items.map(\.url.lastPathComponent) == ["WebKit"])+ }++ /// A folder in a container that did not answer in time is not known to hold only what the app makes again, so a+ /// reset does not offer it: it is not read as empty, and nothing unknown is selected.+ @Test func aFolderInAContainerThatDidNotAnswerInTimeIsNotOffered() async throws {let directory = try TemporaryDirectory()try directory.file("Library/Containers/com.example.app/Data/Library/Caches/cache", bytes: 400_000)try directory.file("Library/Containers/com.example.app/Data/Library/Logs/app.log", bytes: 4096)let reset = await AppReset.prepare(app(), installedApps: [app()], exclusions: .none, environment: home(directory)) { url in- url.lastPathComponent == "Caches" ? nil : await FileSize.allocatedSize(of: url, within: FileSize.budget)+ url.lastPathComponent == "Caches" ? nil : await FileSize.contents(of: url)}- #expect(reset.items.map(\.url.lastPathComponent) == ["Caches", "Logs"])- #expect(reset.items.first?.size == nil)- #expect(!reset.size(of: reset.suggestedSelection).isComplete)+ #expect(reset.items.map(\.url.lastPathComponent) == ["Logs"])+ #expect(reset.size(of: reset.suggestedSelection).isComplete)#expect(reset.size(of: reset.suggestedSelection).known >= 4096)}diff --git a/Peel/Views/ResetSheet.swift b/Peel/Views/ResetSheet.swiftindex 03a00e0e..1e923478 100644--- a/Peel/Views/ResetSheet.swift+++ b/Peel/Views/ResetSheet.swift@@ -116,8 +116,7 @@ struct ResetSheet: View {url: item.url,icon: .symbol(item.kind.symbolName),detail: nil,- size: item.size ?? 0,- isMeasured: item.size != nil,+ size: item.size,isFirst: index == 0,hasNoteColumn: false,selection: plan, isSelected: plan.isSelected(item.url)@@ -322,6 +321,6 @@ struct ResetSheet: View {}private var sizes: [URL: Int64] {- [URL: Int64](measured: plan.items.map { ($0.url, $0.size) })+ Dictionary(plan.items.map { ($0.url, $0.size) }, uniquingKeysWith: { first, _ in first })}}