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
The removal guard looks protected trees up instead of comparing each one
Țugui Dragoșf4a5f666fff9
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/BrowserWallets.swift b/Packages/PeelCore/Sources/PeelPrivileged/BrowserWallets.swiftindex 83e92e3d..6c7f92b7 100644--- a/Packages/PeelCore/Sources/PeelPrivileged/BrowserWallets.swift+++ b/Packages/PeelCore/Sources/PeelPrivileged/BrowserWallets.swift@@ -235,6 +235,9 @@ extension ProtectedData {public static func holdsABrowserWallet(_ path: String) -> Bool {let components = PathComponents.of(path)if let profile = profile(sharedBy: components), isAProfileWithAWallet(profile) { return true }+ // Only a folder can be a profile or hold one.+ var info = stat()+ guard lstat(path, &info) == 0, info.st_mode & S_IFMT == S_IFDIR else { return false }if isAProfileWithAWallet(path) { return true }let folder = components.last?.lowercased() ?? ""diff --git a/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift b/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swiftindex b3bfbd4a..d0fac8d4 100644--- a/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift+++ b/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift@@ -255,21 +255,44 @@ public enum ProtectedData: Sendable {spellings(of: path).contains { spelling inlet names = PathComponents.of(spelling)let holdsIt = { (tree: [String]) in tree.count > names.count && tree.starts(with: names) }- for home in homes(of: spelling, given: home) where trees(under: home).contains(where: holdsIt) {+ for home in homes(of: spelling, given: home) where trees(under: home).sitInside(names) {return true}return systemFolders.contains { holdsIt(PathComponents.of($0.lowercased())) }}}- /// The protected paths for each home, built once, since `refuses` is asked of every entry a scan looks at.+ /// The protected trees under one home, looked up by a path's own names rather than compared with each tree.+ /// Names compare as strings, so a composed letter still matches its decomposed spelling.+ private struct Trees {+ let trees: Set<[String]>+ /// Every folder a tree sits in, from the root down.+ let ancestors: Set<[String]>++ init(_ trees: [[String]]) {+ self.trees = Set(trees)+ ancestors = Set(trees.flatMap { tree in (0..<tree.count).map { Array(tree[..<$0]) } })+ }++ /// True when `names` is a tree or sits inside one.+ func contain(_ names: [String]) -> Bool {+ names.indices.contains { trees.contains(Array(names[...$0])) }+ }++ /// True when a tree sits inside `names`.+ func sitInside(_ names: [String]) -> Bool {+ ancestors.contains(names)+ }+ }++ /// The protected trees for each home, built once, since `refuses` is asked of every entry a scan looks at./// A path can name any home under `/Users`, so the cache is capped rather than left to grow.- private static let treesByHome = Mutex<[String: [[String]]]>([:])+ private static let treesByHome = Mutex<[String: Trees]>([:])- private static func trees(under home: String) -> [[String]] {+ private static func trees(under home: String) -> Trees {treesByHome.withLock { cache inif let trees = cache[home] { return trees }- let trees = (homeFolders + homeKeys + walletKeys).map { PathComponents.of((home as NSString).appendingPathComponent($0).lowercased()) }+ let trees = Trees((homeFolders + homeKeys + walletKeys).map { PathComponents.of((home as NSString).appendingPathComponent($0).lowercased()) })if cache.count >= 32 { cache.removeAll() }cache[home] = treesreturn trees@@ -337,7 +360,7 @@ public enum ProtectedData: Sendable {if isGlobalPreferences(spelling) || isInAnApplesGroupContainer(spelling) { return true }if isInsideAWalletExtension(names) { return true }- for home in homes(of: spelling, given: home) where trees(under: home).contains(where: names.starts(with:)) {+ for home in homes(of: spelling, given: home) where trees(under: home).contain(names) {return true}return systemFolders.contains { names.starts(with: PathComponents.of($0.lowercased())) }