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
Working out a path's spellings splits it once
Țugui Dragoș88e8c472c85d
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift b/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swiftindex 98aabe9d..2e381249 100644--- a/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift+++ b/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift@@ -340,7 +340,11 @@ public enum ProtectedData: Sendable {/// case-insensitive by default, so one file has several names. A check that knew only one of them could be/// bypassed by writing another.public static func spellings(of path: String) -> Set<String> {- var names = privateNames(of: path).union(privateNames(of: (path as NSString).standardizingPath))+ var names = privateNames(of: path)+ let standardized = (path as NSString).standardizingPath+ if standardized != path {+ names.formUnion(privateNames(of: standardized))+ }let resolved = (path as NSString).resolvingSymlinksInPathif resolved != path {names.formUnion(privateNames(of: resolved))@@ -351,15 +355,15 @@ public enum ProtectedData: Sendable {})}+ private static let linkedIntoPrivate: Set<String> = ["var", "tmp", "etc"]+private static func privateNames(of path: String) -> Set<String> {- for link in ["/var", "/tmp", "/etc"] {- if PathComponents.isPath(path, atOrInside: link) {- return [path, "/private" + path]- }- let inPrivate = "/private" + link- if PathComponents.isPath(path, atOrInside: inPrivate) {- return [path, String(path.dropFirst("/private".count))]- }+ let names = PathComponents.of(path)+ if let first = names.first, linkedIntoPrivate.contains(first) {+ return [path, "/private" + path]+ }+ if names.count > 1, names[0] == "private", linkedIntoPrivate.contains(names[1]) {+ return [path, String(path.dropFirst("/private".count))]}return [path]}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swiftindex 7b6513a4..4274c89e 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift@@ -74,6 +74,14 @@ struct AttackRemovalGuardTests {#expect(temporary.isSuperset(of: ["/private/tmp/org.example.app", "/tmp/org.example.app"]))}+ @Test func theFoldersLinkedIntoPrivateAreAskedBothWays() {+ #expect(ProtectedData.spellings(of: "/var/db/org.example.app").isSuperset(of: ["/var/db/org.example.app", "/private/var/db/org.example.app"]))+ #expect(ProtectedData.spellings(of: "/private/etc/org.example.conf").isSuperset(of: ["/private/etc/org.example.conf", "/etc/org.example.conf"]))+ #expect(ProtectedData.spellings(of: "/tmp").isSuperset(of: ["/tmp", "/private/tmp"]))+ #expect(ProtectedData.spellings(of: "/variable/org.example.app") == ["/variable/org.example.app"])+ #expect(ProtectedData.spellings(of: "/private/variable/org.example.app") == ["/private/variable/org.example.app"])+ }+@Test func caseSpellingOfAProtectedTree() throws {let directory = try TemporaryDirectory()let home = directory.url.appending(path: "home", directoryHint: .isDirectory)