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
Keep an app's folder that holds its backups unselected
Țugui Dragoș7826fecc8cdb
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/KeptOnlyHere.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/KeptOnlyHere.swiftindex c1600495..00b831f9 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/KeptOnlyHere.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/KeptOnlyHere.swift@@ -117,7 +117,15 @@ enum KeptOnlyHere {}}// What an app names as its backups is a copy the person may need, whichever app made it.- let words = (item.last ?? "").split { !$0.isLetter }- return words.contains("backup") || words.contains("backups") ? .holdsWorkMadeWithTheApp : nil+ return namesBackups(item.last ?? "") ? .holdsWorkMadeWithTheApp : nil+ }++ static func reason(seenIn contents: FolderContents) -> HoldBack? {+ contents.holdsBackups ? .holdsWorkMadeWithTheApp : nil+ }++ static func namesBackups(_ name: String) -> Bool {+ let words = name.lowercased().split { !$0.isLetter }+ return words.contains("backup") || words.contains("backups")}}diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swiftindex 253ed8ca..91fda49d 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift@@ -447,6 +447,7 @@ public struct LeftoverScanner: Sendable {// are. Holding it back costs a checkmark, and the row says what is inside.if let secret = HoldBack.secret(in: contents) { return secret }if contents.holdsRepository { return .holdsRepository }+ if let backups = KeptOnlyHere.reason(seenIn: contents) { return backups }if kind == .logs, CrashReport.isOne(url) { return .crashReport }if kind == .sharedFolder { return .sharedWithEveryone }if Self.namedGroundOfSomebodyElse.contains(kind), match.restsOnAName { return .namedLikeTheApp }diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swiftindex 5096a6f8..a4a8a3ff 100644--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift@@ -785,8 +785,8 @@ public struct OrphanScanner: Sendable {.crashReport} else {// `/Users/Shared` belongs to every account on the Mac, and the other accounts' apps are not known here.- HoldBack.seen(in: contents) ?? (kind == .sharedFolder ? .sharedWithEveryone : nil)- ?? (namedAfter != nil ? .namedLikeTheApp : nil)+ HoldBack.seen(in: contents) ?? contents.flatMap(KeptOnlyHere.reason(seenIn:))+ ?? (kind == .sharedFolder ? .sharedWithEveryone : nil) ?? (namedAfter != nil ? .namedLikeTheApp : nil)}return OrphanItem(url: url,diff --git a/Packages/PeelCore/Sources/PeelCore/Support/FileSize.swift b/Packages/PeelCore/Sources/PeelCore/Support/FileSize.swiftindex 2d9d5244..8ec93730 100644--- a/Packages/PeelCore/Sources/PeelCore/Support/FileSize.swift+++ b/Packages/PeelCore/Sources/PeelCore/Support/FileSize.swift@@ -15,6 +15,8 @@ public struct FolderContents: Sendable, Hashable {public let holdsWallet: Bool/// True when a password database or its key file was seen inside (`isPasswordDatabase(_:)`).public let holdsPasswordDatabase: Bool+ /// True when something directly inside is named as backups: a file, or a folder that holds something.+ public let holdsBackups: Bool/// The latest modification date of anything inside. A folder's own date does not change when a file in/// it is rewritten in place.public let newestChange: Date?@@ -35,6 +37,7 @@ public struct FolderContents: Sendable, Hashable {holdsRepository: Bool,holdsWallet: Bool = false,holdsPasswordDatabase: Bool = false,+ holdsBackups: Bool = false,newestChange: Date? = nil,couldNotBeRead: Bool = false,taken: Int64? = nil@@ -44,6 +47,7 @@ public struct FolderContents: Sendable, Hashable {self.holdsRepository = holdsRepositoryself.holdsWallet = holdsWalletself.holdsPasswordDatabase = holdsPasswordDatabase+ self.holdsBackups = holdsBackupsself.newestChange = newestChangeself.couldNotBeRead = couldNotBeRead}@@ -204,6 +208,7 @@ public enum FileSize {var holdsRepository = repositoryMarkers.contains(url.lastPathComponent)var holdsWallet = isWallet(url.lastPathComponent)var holdsPasswordDatabase = isPasswordDatabase(url.lastPathComponent)+ var holdsBackups = falsevar newestChange: Date?// A file with several names goes only once every name has gone, so it counts once, and only when all of// its names are inside.@@ -220,6 +225,10 @@ public enum FileSize {if repositoryMarkers.contains(file.lastPathComponent) { holdsRepository = true }if isWallet(file.lastPathComponent) { holdsWallet = true }if isPasswordDatabase(file.lastPathComponent) { holdsPasswordDatabase = true }+ if !holdsBackups, enumerator.level == 2,+ KeptOnlyHere.namesBackups(file.deletingLastPathComponent().lastPathComponent) {+ holdsBackups = true+ }guard let values = try? file.resourceValues(forKeys: fileKeys) else { return .next }if let written = values.contentModificationDate, written > newestChange ?? .distantPast {newestChange = written@@ -228,6 +237,9 @@ public enum FileSize {if isDataless(file) { enumerator.skipDescendants() }return .next}+ if !holdsBackups, enumerator.level == 1, KeptOnlyHere.namesBackups(file.lastPathComponent) {+ holdsBackups = true+ }if let links = values.linkCount, links > 1, let identifier = values.fileIdentifier {severalNames[identifier, default: (0, links, Int64(values.totalFileAllocatedSize ?? 0))].seen += 1return .next@@ -249,6 +261,7 @@ public enum FileSize {holdsRepository: holdsRepository,holdsWallet: holdsWallet,holdsPasswordDatabase: holdsPasswordDatabase,+ holdsBackups: holdsBackups,newestChange: newestChange,couldNotBeRead: refused.happened,taken: takendiff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swiftindex 8859d4af..e8ceda3c 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swift@@ -474,6 +474,27 @@ struct FileSizeTests {}}+ @Test func reportsBackupsKeptDirectlyInside() async throws {+ let directory = try TemporaryDirectory()+ let novels = try directory.directory("novels")+ try directory.file("novels/Backups/My Novel.bak.zip", bytes: 64)+ let library = try directory.directory("library")+ try directory.file("library/library-backup.sqlite", bytes: 64)+ let empty = try directory.directory("empty")+ try directory.directory("empty/Backups")+ let deeper = try directory.directory("deeper")+ try directory.file("deeper/User/globalStorage/state.vscdb.backup", bytes: 64)+ let lookalike = try directory.directory("lookalike")+ try directory.file("lookalike/Backupify/settings.json", bytes: 64)++ for folder in [novels, library] {+ #expect(await FileSize.contents(of: folder)?.holdsBackups == true, "\(folder.lastPathComponent)")+ }+ for folder in [empty, deeper, lookalike] {+ #expect(await FileSize.contents(of: folder)?.holdsBackups == false, "\(folder.lastPathComponent)")+ }+ }+/// The names wallets and their keys go by, as each project's documentation or source gives them, and names/// that only look close.@Test func knowsTheNamesWalletsAndTheirKeysGoBy() {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swiftindex c566c800..81234b9b 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift@@ -53,6 +53,33 @@ struct LeftoverScannerTests {#expect(!plan.scan.leftovers.contains { $0.url.lastPathComponent == ".org.example.app.plist" })}+ @Test func leavesTheAppsFolderThatHoldsItsBackupsForThePersonToSelect() async throws {+ let directory = try TemporaryDirectory()+ try directory.file("home/Library/Application Support/Quillworks/Backups/My Novel.bak.zip", bytes: 64)+ try directory.file("home/Library/Application Support/Quillworks/Settings.plist", bytes: 64)+ try directory.directory("home/Library/Application Support/Inkpot/Backups")+ try directory.file("home/Library/Application Support/Inkpot/Settings.plist", bytes: 64)+ let quillworks = InstalledApp(+ url: URL(filePath: "/Applications/Quillworks.app"), bundleIdentifier: "org.example.quillworks",+ name: "Quillworks"+ )+ let inkpot = InstalledApp(+ url: URL(filePath: "/Applications/Inkpot.app"), bundleIdentifier: "org.example.inkpot", name: "Inkpot"+ )+ let apps = [quillworks, inkpot]+ let environment = environment(in: directory)++ let kept = await Uninstallation.prepare(quillworks, installedApps: apps, environment: environment)+ let free = await Uninstallation.prepare(inkpot, installedApps: apps, environment: environment)++ let folder = try #require(kept.scan.leftovers.first { $0.url.lastPathComponent == "Quillworks" })+ #expect(folder.match.heldBack == .holdsWorkMadeWithTheApp)+ #expect(!kept.suggestedSelection(canUseHelper: false).contains(folder.url))+ let control = try #require(free.scan.leftovers.first { $0.url.lastPathComponent == "Inkpot" })+ #expect(control.match.heldBack == nil)+ #expect(free.suggestedSelection(canUseHelper: false).contains(control.url))+ }+/// Folders that no app claims are looked into one at a time, so the scan has to notice a stop between them.@Test func aStoppedScanStops() async throws {let directory = try TemporaryDirectory()diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swiftindex d16fd0d2..142336fb 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift@@ -247,6 +247,27 @@ struct OrphanScannerTests {#expect(await scanner.stillOrphaned([item], installedApps: installed + [back], remembered: [editor]).isEmpty)}+ @Test func holdsBackAGoneAppsFolderThatHoldsItsBackups() async throws {+ let directory = try TemporaryDirectory()+ try directory.file("home/Library/Application Support/org.example.quillworks/Backups/My Novel.bak.zip", bytes: 64)+ try directory.file("home/Library/Application Support/org.example.inkpot/Settings.plist", bytes: 64)+ let gone = { (identifier: String, name: String) in+ RememberedApp(+ bundleIdentifier: identifier, name: name, teamIdentifier: nil, lastSeen: .now,+ lastPath: "/Applications/\(name).app"+ )+ }++ let scan = await scanner(in: directory).scan(+ installedApps: installed,+ remembered: [gone("org.example.quillworks", "Quillworks"), gone("org.example.inkpot", "Inkpot")]+ )++ let items = scan.groups.flatMap(\.items)+ #expect(items.first { $0.url.lastPathComponent == "org.example.quillworks" }?.heldBack == .holdsWorkMadeWithTheApp)+ #expect(items.contains { $0.url.lastPathComponent == "org.example.inkpot" && $0.heldBack == nil })+ }+@Test func listsABrowsersManifestThatStartsNothing() async throws {let directory = try TemporaryDirectory()let hosts = "root/Library/Google/Chrome/NativeMessagingHosts"diff --git a/SAFETY.md b/SAFETY.mdindex 3e747a8e..119fba31 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -390,9 +390,9 @@ Never selected for you, even when found:backups and an authenticator's codes, VPN connections and identities, a torrent client's list of torrents, a game'ssaves, a database, a streaming app's scenes and profiles, an office suite's own templates and dictionaries, aterminal's scripts and profiles, and the sign-in a tool saved when you logged in, such as Docker's or Cargo's, each- where the app's own documentation or source says it keeps them, and anything named as an app's backups. When you- uninstall Xcode, the simulators it made in your home folder are listed too, with the apps installed in them and their- data, and never selected.+ where the app's own documentation or source says it keeps them, and anything named as an app's backups, or the+ app's folder that keeps them. When you uninstall Xcode, the simulators it made in your home folder are listed too,+ with the apps installed in them and their data, and never selected.- A copy Mail keeps of an attachment you opened, which you may have changed.- A file a program has open right now.- An installer package an app keeps in Application Support, which the app may still need, and an update whose app is