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.

Prove no folder is counted twice, whatever the patterns reach

Țugui Dragoș5952a9296180
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
index a464f9b3..42619234 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
@@ -517,10 +517,15 @@ struct DeveloperCachesTests {
)
let environments = await DeveloperCaches.scan(in: environment)
let home = directory.url.path(percentEncoded: false)
- let found = Set(
- environments.flatMap(\.locations).map { String($0.url.path(percentEncoded: false).dropFirst(home.count)) }
- )
+ let offered = environments.flatMap(\.locations).map { location in
+ String(location.url.path(percentEncoded: false).dropFirst(home.count))
+ }
+ let found = Set(offered)
#expect(found == expected, "missing \(expected.subtracting(found).sorted()), extra \(found.subtracting(expected).sorted())")
+ // Two entries whose patterns reach the same folder, or one inside the other, would count its bytes twice.
+ #expect(offered.count == found.count, "offered twice: \(offered.filter { path in offered.count { $0 == path } > 1 })")
+ let nested = offered.filter { path in offered.contains { $0 != path && path.hasPrefix($0 + "/") } }
+ #expect(nested.isEmpty, "offered inside another: \(nested.sorted())")
#expect(environments.count == DeveloperCaches.definitions.count)
#expect(environments.flatMap(\.locations).allSatisfy { ($0.size ?? 0) >= 400_000 })
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SpaceInventoryTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SpaceInventoryTests.swift
index 5d10be2b..94ef1f4c 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/SpaceInventoryTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/SpaceInventoryTests.swift
@@ -299,10 +299,24 @@ struct SpaceInventoryTests {
let report = await SpaceInventory.scan(home: home, root: root, minimumSize: 1, measure: FileSize.measure)
let inside = directory.url.lastPathComponent + "/"
- let found = Set(report.items.flatMap { item in
- item.urls.map { "\(item.id): \($0.path(percentEncoded: false).components(separatedBy: inside).last ?? "")" }
- }.map { $0.hasSuffix("/") ? String($0.dropLast()) : $0 })
+ let places = report.items.flatMap { item in
+ item.urls.map { url in
+ let path = url.path(percentEncoded: false).components(separatedBy: inside).last ?? ""
+ return (item: item, path: path.hasSuffix("/") ? String(path.dropLast()) : path)
+ }
+ }
+ let found = Set(places.map { "\($0.item.id): \($0.path)" })
#expect(expected.subtracting(found).isEmpty, "\(expected.subtracting(found).sorted())")
+ // A place in two areas, or inside a place measured whole, would count its bytes twice in the total. An area
+ // that leaves macOS's own measures what is in its places one by one, and passes over a place of its own.
+ let twice = places.filter { place in
+ places.contains { other in
+ let isAnotherArea = other.item.id != place.item.id
+ return (other.path == place.path && isAnotherArea)
+ || (place.path.hasPrefix(other.path + "/") && (isAnotherArea || !other.item.leavesMacOSsOwn))
+ }
+ }
+ #expect(twice.isEmpty, "counted twice: \(twice.map(\.path).sorted())")
}
@Test func everyDefinitionSaysWhatItIsAndWhoOwnsIt() {