Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Space never plans to move anything from an area its tool empties

Țugui Dragoș9199500fbd83
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift
index 54f1d7d0..c0da99ed 100644
--- a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift
@@ -109,6 +109,8 @@ public enum SpaceRemoval {
exclusions: Exclusions,
running: [String: String]
) -> (removable: [URL], inUse: [(url: URL, name: String)], leftToDeveloper: [URL], refused: [URL: GuardRefusal]) {
+ // An area only its own app or tool should empty, such as a virtual machine's disks, offers nothing.
+ guard item.handling == .trash else { return ([], [], [], [:]) }
let removalGuard = RemovalGuard(environment: environment, exclusions: exclusions)
var removable: [URL] = []
var inUse: [(url: URL, name: String)] = []
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift
index 18b93cd0..5cf6f54b 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift
@@ -23,6 +23,26 @@ struct SpaceRemovalTests {
)
}
+ /// An area only its own app or tool should empty, such as a virtual machine's disks, is never planned for the
+ /// Trash, whoever asks.
+ @Test func plansNothingInAnAreaItsOwnToolEmpties() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("home/Library/Containers/org.example.vm/Data/vms/0/disk.img", bytes: 64)
+ let machines = SpaceItem(
+ id: "virtual-machines",
+ category: .virtualMachines,
+ urls: [directory.url.appending(path: "home/Library/Containers/org.example.vm/Data/vms", directoryHint: .isDirectory)],
+ size: 64,
+ handling: .readOnly
+ )
+
+ let plan = await SpaceRemoval.plan(for: machines, environment: environment(directory))
+ let removable = await SpaceRemoval.removable(in: machines, environment: environment(directory))
+
+ #expect(plan.removable.isEmpty)
+ #expect(removable.isEmpty)
+ }
+
/// Space moves each folder inside Caches whole, but Coursier's folder holds the JVMs that `JAVA_HOME` points
/// at, and Poetry's holds its virtual environments. Only Developer knows which part of such a folder is a cache.
@Test func leavesToDeveloperEveryFolderDeveloperListsSomethingInside() async throws {