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 folder that holds a wallet's keys
Țugui Dragoș7052e9d3e4f9
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swiftindex d227444d..176b070b 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift@@ -217,15 +217,16 @@ public struct LeftoverScanner: Sendable {// A folder that did not answer in time is unknown, not empty: it may hold a repository, and the largest// folders are the ones that run out of time.let contents = await measure(url)- // A folder macOS refuses to open would read as empty, and an empty folder of the app's own would be- // selected. From macOS 27, another team's container is refused outright rather than prompted for.- let heldBack: HoldBack? = if contents?.couldNotBeRead == true {+ // Where a protected key lies is known from the path alone, so that reason comes first. A folder macOS+ // refuses to open would read as empty, and an empty folder of the app's own would be selected. From+ // macOS 27, another team's container is refused outright rather than prompted for.+ let heldBack: HoldBack? = if ProtectedData.holds(url.path(percentEncoded: false), home: home)+ || ProtectedData.holdsABrowserWallet(url.path(percentEncoded: false)) {+ .holdsKeys+ } else if contents?.couldNotBeRead == true {.couldNotBeRead} else if kind == .containers, ProtectedData.holdsAContainersDocuments(url.path(percentEncoded: false)) {.holdsDocuments- } else if ProtectedData.holds(url.path(percentEncoded: false), home: home)- || ProtectedData.holdsABrowserWallet(url.path(percentEncoded: false)) {- .holdsKeys} else if ProtectedData.holdsALibrary(url.path(percentEncoded: false)) {.holdsALibrary} else if let contents {diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swift b/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swiftindex 234b0665..ef529b83 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swift@@ -1,4 +1,5 @@public import Foundation+internal import PeelPrivileged/// The files a reset can clear for an app, so the app starts fresh without being uninstalled. The app itself,/// its launch agents and its helper tools are never part of a reset: removing them would break the app.@@ -120,13 +121,15 @@ public struct AppReset: Sendable {}let scan = await LeftoverScanner(environment: environment, exclusions: exclusions).scan(app, installedApps: installedApps)let keepsAppData = dataIsNeverOffered.contains(app.bundleIdentifier)- // A container held back because of the documents inside it is still looked into: a reset never touches- // `Documents`, and the settings next to them are what a reset is for.+ // A container held back because of the documents or a wallet's keys inside it is still looked into: a reset+ // never touches `Documents`, never offers a folder that holds keys, and the settings beside them are what a+ // reset is for.let usable = scan.leftovers.filter { leftover in// Only `certain`, never `likely`: a reset ends in `defaults delete`, and a display name or an unlisted// prefix may also belong to something else (an app called Yarn, and the Yarn command-line tool).let isCertainlyTheApps = leftover.match.confidence == .certain && !leftover.match.isShared- let isOffered = leftover.match.heldBack == nil || (leftover.kind == .containers && leftover.match.heldBack == .holdsDocuments)+ let isOffered = leftover.match.heldBack == nil+ || (leftover.kind == .containers && [.holdsDocuments, .holdsKeys].contains(leftover.match.heldBack))return isCertainlyTheApps && isOffered && !leftover.requiresPrivileges}@@ -146,7 +149,7 @@ public struct AppReset: Sendable {needsFullDiskAccess = needsFullDiskAccess || access == .missingcontinue}- items += await itemsInside(container.url, of: app, exclusions: exclusions, measure: measure)+ items += await itemsInside(container.url, of: app, exclusions: exclusions, home: environment.homeDirectory, measure: measure)}return AppReset(@@ -161,12 +164,13 @@ public struct AppReset: Sendable {_ container: URL,of app: InstalledApp,exclusions: Exclusions,+ home: URL,measure: FileSize.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) else { continue }+ 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)))}let preferences = container.appending(path: containerPreferenceFolder, directoryHint: .isDirectory)@@ -181,4 +185,12 @@ public struct AppReset: Sendable {}return items}++ /// True for a folder that holds a wallet's or a key's file `ProtectedData` names, or a browser profile with a+ /// wallet in it, which `RemovalGuard` would refuse to move.+ private static func holdsKeys(_ url: URL, home: URL) -> Bool {+ let path = url.path(percentEncoded: false)+ let home = home.path(percentEncoded: false)+ return ProtectedData.refuses(path, home: home) || ProtectedData.holds(path, home: home) || ProtectedData.holdsABrowserWallet(path)+ }}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swiftindex 100aedf0..0458d406 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swift@@ -143,6 +143,26 @@ struct AppResetTests {#expect(!reset.needsFullDiskAccess)}+ /// A wallet can keep its keys in its container's `Caches`, as BlueWallet does. A reset still clears the settings+ /// beside them, with documents in the container or without, and never offers the folder that holds the keys.+ @Test func neverOffersAFolderInAContainerThatHoldsAWallet() async throws {+ for hasDocuments in [false, true] {+ let directory = try TemporaryDirectory()+ let blueWallet = app("io.bluewallet.bluewallet", name: "BlueWallet")+ try directory.file("Library/Containers/io.bluewallet.bluewallet/Data/Library/Caches/keyvalue.realm", bytes: 4096)+ try directory.file("Library/Containers/io.bluewallet.bluewallet/Data/Library/Cookies/jar", bytes: 4096)+ if hasDocuments {+ try directory.file("Library/Containers/io.bluewallet.bluewallet/Data/Documents/export.pdf", bytes: 4096)+ }++ let reset = await AppReset.prepare(blueWallet, installedApps: [blueWallet], environment: home(directory))+ let names = Set(reset.items.map(\.url.lastPathComponent))++ #expect(names.contains("Cookies"), "the settings beside the wallet were not offered")+ #expect(!names.contains("Caches"), "the folder holding the wallet was offered")+ }+ }+@Test func keepsTheDataInsideAContainerWhenTheAppIsOneOfTheFour() async throws {let directory = try TemporaryDirectory()try directory.file("Library/Containers/com.apple.Notes/Data/Library/Preferences/com.apple.Notes.plist", bytes: 4096)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swiftindex 9e7d34e5..e878d754 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift@@ -561,6 +561,24 @@ struct LeftoverScannerTests {#expect(folder.match.heldBack?.cannotBeMoved == true)}+ /// Where a key Peel protects lies is known from the path alone, so a folder macOS will not let Peel read, but+ /// that holds such a key, is shown as one that cannot be selected, not merely as one that was not read.+ @Test func aFolderThatCannotBeReadButHoldsAProtectedKeyCannotBeSelected() async throws {+ let directory = try TemporaryDirectory()+ let folder = try directory.directory("home/Library/Application Support/Litecoin")++ let leftover = await LeftoverScanner.leftover(+ at: folder,+ kind: .applicationSupport,+ match: LeftoverMatch(reason: .bundleIdentifier, confidence: .certain, sharedWith: []),+ parent: ParentAccess(folder.deletingLastPathComponent()),+ home: directory.url.appending(path: "home").path(percentEncoded: false),+ measure: { _ in FolderContents(size: 0, holdsRepository: false, couldNotBeRead: true) }+ )++ #expect(leftover.match.heldBack == .holdsKeys)+ }+/// A browser's folder that holds a profile with a wallet extension cannot be selected either.@Test func aBrowsersFolderHoldingAWalletCannotBeSelected() async throws {let directory = try TemporaryDirectory()diff --git a/SAFETY.md b/SAFETY.mdindex 21dcd968..eb715d6a 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -200,7 +200,8 @@ can be put back or cleared, since one can hold a license key. What the app keepsfolder, group containers, and application scripts) goes only when you select it, and is never offered for Mail,Messages, Notes, or Photos. Inside a sandboxed app's container, a reset touches only the app's preferences, savedstate, caches, logs, and web data, never `Documents`, `Application Support`, or `Autosave Information`; web data,-which signs you out of websites, is offered but never selected for you.+which signs you out of websites, is offered but never selected for you. A folder that holds a wallet's keys is never+offered, even among those: BlueWallet keeps its wallet in its container's caches.## The helper that runs as root