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
List a folder of virtual machines by its items at an uninstall
Țugui Dragoșdd90a937793b
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swiftindex 4ea18611..ff21bca3 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift@@ -440,6 +440,48 @@ public struct LeftoverScan: Sendable {)}+ /// The same scan, each folder the walk saw virtual machines in listed by its own items when one of them isn't a+ /// machine, so the machines stay unselected and the rest, such as the system images they were installed from, is+ /// chosen like anything else. A machine's own package, a container, and a place a maker names stay one row.+ func splittingFoldersOfMachines(+ home: String,+ root: String,+ exclusions: Exclusions,+ refuses: @escaping LeftoverScanner.Refuses = { ProtectedData.refuses($0, home: $1) },+ measure: @escaping LeftoverScanner.Measure = LeftoverScanner.walk+ ) async -> LeftoverScan {+ var split: [Leftover] = []+ for leftover in leftovers {+ let path = leftover.url.path(percentEncoded: false)+ guard leftover.match.heldBack == .holdsVirtualMachines, leftover.kind != .containers,+ !KeptOnlyHere.namesAVirtualMachine(leftover.url.lastPathComponent),+ KeptOnlyHere.reason(for: path, home: home, root: root) == nil, leftover.url.isRealFolder,+ let names = try? FileManager.default.contentsOfDirectory(atPath: path) else {+ split.append(leftover)+ continue+ }+ var match = leftover.match+ match.heldBack = nil+ let children = names.sorted().map { leftover.url.appending(path: $0) }.filter {+ !refuses($0.path(percentEncoded: false), home) && !exclusions.excludes($0)+ && !FileAccess.cannotBeRemoved($0)+ }+ let items = await children.concurrentMap(width: LeftoverScanner.concurrentMeasurements) { [match] child in+ await LeftoverScanner.leftover(+ at: child, kind: leftover.kind, match: match, parent: ParentAccess(leftover.url), home: home,+ root: root, measure: measure+ )+ }+ split += items.contains { $0.match.heldBack != .holdsVirtualMachines } ? items : [leftover]+ }+ return LeftoverScan(+ leftovers: split.sorted(by: Leftover.comesBefore),+ unreadableLocations: unreadableLocations,+ cutShortLocations: cutShortLocations,+ needsFullDiskAccess: needsFullDiskAccess+ )+ }+/// Adds findings the scanner didn't see, keeping what it already knows about a path.public func adding(_ extra: [Leftover]) -> LeftoverScan {// By what each item is on the disk, not by its spelling: a cask can write a folder in another case, or withdiff --git a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swiftindex 76794215..2311d661 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift@@ -82,6 +82,11 @@ public struct Uninstallation: Sendable {environment: environment))+ scan = await scan.splittingFoldersOfMachines(+ home: environment.homeDirectory.path(percentEncoded: false),+ root: environment.rootDirectory.path(percentEncoded: false),+ exclusions: exclusions+ )scan = scan.holdingBack(placesOthersKeep: matcher.placesOthersKeep(home: environment.homeDirectory))let uninstallsItself = UninstallsItself.of(app, environment: environment)if let uninstallsItself {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swiftindex 1932ab78..dca682c0 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift@@ -210,6 +210,37 @@ struct UninstallationTests {#expect(!plan.selectable(canUseHelper: true).contains(leftover.url))}+ @Test func listsAFolderOfMachinesByItsItemsSoOnlyItsMachinesStayUnselected() async throws {+ let directory = try TemporaryDirectory()+ let app = InstalledApp(+ url: try directory.directory("root/Applications/Tidewater.app"), bundleIdentifier: "org.example.tidewater",+ name: "Tidewater"+ )+ try directory.file("home/Library/Application Support/Tidewater/Sonoma.vbvm/Disk.img", bytes: 64)+ try directory.file("home/Library/Application Support/Tidewater/_Downloads/UniversalMac_Restore.ipsw", bytes: 64)+ try directory.file("home/Library/Application Support/Tidewater/_GuestImage/guest.dmg", bytes: 64)+ try directory.file("home/Library/Application Support/org.example.tidewater/Ventura.vbvm/Disk.img", bytes: 64)+ let environment = SearchEnvironment(+ homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),+ rootDirectory: directory.url.appending(path: "root", directoryHint: .isDirectory)+ )++ let plan = await Uninstallation.prepare(app, installedApps: [app], environment: environment)++ let rows = Dictionary(uniqueKeysWithValues: plan.scan.leftovers.map {+ (PathPattern.comparablePath(of: $0.url), $0.match)+ })+ let support = PathPattern.comparablePath(+ of: environment.homeDirectory.appending(path: "Library/Application Support")+ )+ #expect(rows["\(support)/Tidewater"] == nil)+ #expect(rows["\(support)/Tidewater/Sonoma.vbvm"]?.heldBack == .holdsVirtualMachines)+ #expect(rows["\(support)/Tidewater/_Downloads"]?.isRecommended == true)+ #expect(rows["\(support)/Tidewater/_GuestImage"]?.isRecommended == true)+ #expect(rows["\(support)/org.example.tidewater"]?.heldBack == .holdsVirtualMachines)+ #expect(rows["\(support)/org.example.tidewater/Ventura.vbvm"] == nil)+ }+@Test func holdsBackAnAudioPlugInOtherAppsLoad() async throws {let directory = try TemporaryDirectory()let app = InstalledApp(