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
Name a file a cask or a receipt points to as the disk names it
Țugui Dragoșe5cdb3713f53
diff --git a/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift b/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swiftindex 6838893a..1a99c3ff 100644--- a/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift+++ b/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift@@ -10,7 +10,7 @@ public enum PackageActions {static func receiptFiles(of identifier: String, onVolume volume: URL) -> [URL] {guard !identifier.isEmpty, !identifier.hasPrefix("."), !identifier.contains("/") else { return [] }return ["bom", "plist"].map { receiptsFolder(onVolume: volume).appending(path: identifier + "." + $0) }- .filter(\.isThere)+ .filter(\.isThere).map(PathPattern.spelledOnDisk)}private static func receiptsFolder(onVolume volume: URL) -> URL {diff --git a/Packages/PeelCore/Sources/PeelCore/Support/PathPattern.swift b/Packages/PeelCore/Sources/PeelCore/Support/PathPattern.swiftindex 27c7b3cd..a61e24d5 100644--- a/Packages/PeelCore/Sources/PeelCore/Support/PathPattern.swift+++ b/Packages/PeelCore/Sources/PeelCore/Support/PathPattern.swift@@ -188,6 +188,22 @@ public enum PathPattern {/// The entry `path` names. A path that ends in `/` names folders only, and the kernel follows a link to what it/// leads to when the slash is kept, so the entry is named without it.private static func entry(named path: String) -> URL {- URL(filePath: path.count > 1 && path.hasSuffix("/") ? String(path.dropLast()) : path)+ spelledOnDisk(URL(filePath: path.count > 1 && path.hasSuffix("/") ? String(path.dropLast()) : path))+ }++ /// `url` with each name the disk holds written as the disk writes it. The disk answers to a name in other+ /// capitals, as a cask or a receipt's identifier may write one, and an item named that way would be shown, recorded+ /// and put back under a name that is not its own. Read without opening anything or following a link.+ static func spelledOnDisk(_ url: URL) -> URL {+ var spelled: [String] = []+ var isOnDisk = true+ for name in PathComponents.of(url.path(percentEncoded: false)) {+ let place = URL(filePath: "/" + (spelled + [name]).joined(separator: "/"), directoryHint: .notDirectory)+ let onDisk = isOnDisk ? (try? place.resourceValues(forKeys: [.nameKey]))?.name : nil+ isOnDisk = onDisk != nil+ spelled.append(onDisk ?? name)+ }+ let path = "/" + spelled.joined(separator: "/")+ return URL(filePath: path, directoryHint: url.hasDirectoryPath ? .isDirectory : .notDirectory)}}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swiftindex cecdc1ef..3f96d8a7 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swift@@ -26,6 +26,16 @@ struct PackageActionsTests {#expect(files.map(\.lastPathComponent).sorted() == ["com.example.tool.bom", "com.example.tool.plist"])}+ @Test func namesAReceiptAsTheDiskWritesIt() throws {+ let directory = try TemporaryDirectory()+ try directory.file("private/var/db/receipts/com.Example.Tool.bom")+ try directory.file("private/var/db/receipts/com.Example.Tool.plist")++ let files = PackageActions.receiptFiles(of: "com.example.tool", onVolume: directory.url)++ #expect(files.map(\.lastPathComponent).sorted() == ["com.Example.Tool.bom", "com.Example.Tool.plist"])+ }+/// The identifier becomes part of a file name, so one that could name anything other than a plain file in/// the receipts folder names nothing.@Test func anIdentifierThatIsAPathNamesNoReceipt() throws {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PathPatternTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PathPatternTests.swiftindex 13604289..e75bfed7 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/PathPatternTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/PathPatternTests.swift@@ -57,6 +57,25 @@ struct PathPatternTests {#expect(whole.count == 300)}+ @Test func aPathWrittenInOtherCapitalsComesBackAsTheDiskWritesIt() throws {+ let directory = try TemporaryDirectory()+ try directory.file("Library/LaunchAgents/com.example.agent.plist")+ try directory.directory("Library/Caches/ExampleApp")+ let versions = try directory.directory("Library/Frameworks/Example.framework/Versions/A").deletingLastPathComponent()+ try FileManager.default.createSymbolicLink(+ atPath: versions.appending(path: "Current").path(percentEncoded: false), withDestinationPath: "A"+ )+ let found = { (pattern: String, source: PathPattern.Source) in+ PathPattern.expand(pattern, home: directory.url, from: source)+ .map { $0.pathComponents.suffix(3).joined(separator: "/") }+ }++ #expect(found("~/Library/LaunchAgents/com.Example.Agent.plist", .cask) == ["Library/LaunchAgents/com.example.agent.plist"])+ #expect(found("~/library/caches/Example*", .cask) == ["Library/Caches/ExampleApp"])+ #expect(found("library/caches/exampleapp", .peel) == ["Library/Caches/ExampleApp"])+ #expect(found("~/Library/Frameworks/example.framework/versions/current", .cask) == ["Example.framework/Versions/Current"])+ }+/// A bracket in a real name is not a character class: `App [Beta]` has to find itself.@Test func findsAFolderWhoseNameHoldsABracket() throws {let directory = try TemporaryDirectory()