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.

Every spelling of a folder too broad to exclude is refused

Țugui Dragoșc8ce3d04e846
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift b/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
index fdda4345..6ece9188 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
@@ -148,17 +148,13 @@ public struct Exclusions: Sendable, Codable, Hashable {
extension Exclusions {
/// True for a path too broad to exclude: `/`, a folder at the top of the disk, the home folder, or its
/// Library. Excluding one would leave the tools with little or nothing to show, and `/` would protect
- /// nothing at all, since a bare `/` would match everything and is ignored.
+ /// nothing at all, since a bare `/` would match everything and is ignored. It is judged on every spelling
+ /// matching reads, so the same folder written in another case is as broad.
public static func isTooBroad(_ url: URL, home: URL = .homeDirectory) -> Bool {
- func plain(_ url: URL) -> String {
- var path = url.standardizedFileURL.path(percentEncoded: false)
- while path.count > 1, path.hasSuffix("/") { path.removeLast() }
- return path
- }
- let path = plain(url)
- let home = plain(home)
- let broad = ["/", home, home + "/Library", "/Applications", "/Library", "/System", "/Users", "/Volumes"]
- return broad.contains(path) || PathComponents.of(path).count < 2
+ let topFolders = ["/Applications", "/Library", "/System", "/Users", "/Volumes"].map { URL(filePath: $0) }
+ let broad = Set(([home, home.appending(path: "Library")] + topFolders).flatMap(spellings(of:)))
+ let asked = spellings(of: url)
+ return asked.contains { PathComponents.of($0).count < 2 } || !asked.isDisjoint(with: broad)
}
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift
index c469878d..7e4bcc9f 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift
@@ -449,6 +449,10 @@ struct ExclusionsReachEveryScannerTests {
for path in ["/", "/Users/me", "/Users/me/", "/Users/me/Library", "/Applications", "/Library", "/System", "/Users", "/Volumes", "/opt"] {
#expect(Exclusions.isTooBroad(URL(filePath: path), home: home), "\(path) was allowed")
}
+ // Matching folds case and reads a path name by name, so the same folders written otherwise are as broad.
+ for path in ["/users/me", "/USERS/ME/library", "/Users/me/./Library", "/Users/me/Documents/../Library", "/library"] {
+ #expect(Exclusions.isTooBroad(URL(filePath: path), home: home), "\(path) was allowed")
+ }
for path in ["/Users/me/Documents/Keep", "/Users/me/Library/Application Support/Acme", "/Applications/Acme.app", "/Volumes/Work/Acme"] {
#expect(!Exclusions.isTooBroad(URL(filePath: path), home: home), "\(path) was refused")
}