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
Apps with identifiers like md.obsidian can be reset
Țugui Dragoș60d1f5a9c0d7
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swiftindex f86656a0..ccb2603f 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift@@ -288,11 +288,11 @@ extension LeftoverMatcher {guard !candidate.isApple || isApplesOwn else { return nil }if key == identifier {- guard Identifier.isReverseDNS(key) else { return Evidence(unproven: .bundleIdentifier, for: candidate) }+ guard Identifier.isValid(key) else { return Evidence(unproven: .bundleIdentifier, for: candidate) }return Evidence(.bundleIdentifier, .certain, specificity: key.count)}if let embedded = embeddedIdentifiers.first(where: { $0.value == key }) {- guard Identifier.isReverseDNS(key) else { return Evidence(unproven: .embeddedBundleIdentifier, for: candidate) }+ guard Identifier.isValid(key) else { return Evidence(unproven: .embeddedBundleIdentifier, for: candidate) }return Evidence(.embeddedBundleIdentifier, embedded.sharesVendor ? .certain : .likely, specificity: key.count)}if applicationGroups.contains(key) {diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swiftindex 416f8cf2..445b68dd 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift@@ -51,7 +51,19 @@ enum Identifier {identifier.split(separator: ".").count}- /// "com.example.app": at least three components and a lowercase top-level domain.+ /// Whether an identifier an app declares is shaped like one app's: two components or more (Obsidian's is+ /// `md.obsidian`), none empty, only ASCII letters, digits, `-` and `_`, and no leading `-`. A single word, or+ /// anything else, is too generic to prove what it names.+ static func isValid(_ identifier: String) -> Bool {+ let components = identifier.split(separator: ".", omittingEmptySubsequences: false)+ guard components.count >= 2, !identifier.hasPrefix("-") else { return false }+ return components.allSatisfy { component in+ !component.isEmpty && component.allSatisfy { $0.isASCII && ($0.isLetter || $0.isNumber || $0 == "-" || $0 == "_") }+ }+ }++ /// Whether a name found on disk reads as an app's identifier, "com.example.app": at least three components and a+ /// lowercase top-level domain. Stricter than `isValid`, since a name nobody declared is only a guess.static func isReverseDNS(_ identifier: String) -> Bool {let components = identifier.split(separator: ".", omittingEmptySubsequences: false)guarddiff --git a/Packages/PeelCore/Sources/PeelCore/Removal/PreferenceBackup.swift b/Packages/PeelCore/Sources/PeelCore/Removal/PreferenceBackup.swiftindex 709a7da8..7f19a7ae 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/PreferenceBackup.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/PreferenceBackup.swift@@ -63,9 +63,9 @@ public enum PreferenceBackup {guard !domains.isEmpty else { return .nothingToSave }// The bundle identifier comes from the app itself and becomes part of a folder name, so it must have the- // reverse DNS shape `copies` reads back, which rules out a `/`.+ // shape `copies` reads back, which rules out a `/` and a space.guard- Identifier.isReverseDNS(bundleIdentifier),+ Identifier.isValid(bundleIdentifier),(try? FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)) != nil,let folder = newFolder(for: bundleIdentifier, in: directory)else { return .failed }@@ -163,7 +163,7 @@ public enum PreferenceBackup {// An identifier has no space, so the name reads as the identifier, the day, the time, and a number.let parts = folder.lastPathComponent.split(separator: " ", omittingEmptySubsequences: false).map(String.init)- guard folder.isRealFolder, parts.count == 3 || parts.count == 4, Identifier.isReverseDNS(parts[0]),+ guard folder.isRealFolder, parts.count == 3 || parts.count == 4, Identifier.isValid(parts[0]),let date = try? stampStyle.parse("\(parts[1]) \(parts[2])") else { return nil }let number = parts.count == 4 ? Int(parts[3]) : 1guard let number, number >= 1 else { return nil }diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/PrivacyReset.swift b/Packages/PeelCore/Sources/PeelCore/Removal/PrivacyReset.swiftindex b3749ef3..bc297e97 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/PrivacyReset.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/PrivacyReset.swift@@ -65,17 +65,12 @@ public enum PrivacyReset {}/// True when `bundleIdentifier` may be handed to `tccutil`. Apple's own apps and every part of Peel are- /// refused. Any other identifier must read as exactly one app's: two components or more (Obsidian's is- /// `md.obsidian`), none empty, only ASCII letters, digits, `-` and `_`, and no leading `-`. This matters+ /// refused, and any other identifier must read as exactly one app's (`Identifier.isValid`). This matters/// because `tccutil reset All` with no identifier resets every app.public static func isAllowed(bundleIdentifier: String) -> Bool {let identifier = bundleIdentifier.lowercased()let own = HelperIdentity.appIdentifier.lowercased()guard !identifier.hasPrefix("com.apple."), identifier != own, !identifier.hasPrefix(own + ".") else { return false }- let components = bundleIdentifier.split(separator: ".", omittingEmptySubsequences: false)- guard components.count >= 2, !bundleIdentifier.hasPrefix("-") else { return false }- return components.allSatisfy { component in- !component.isEmpty && component.allSatisfy { $0.isASCII && ($0.isLetter || $0.isNumber || $0 == "-" || $0 == "_") }- }+ return Identifier.isValid(bundleIdentifier)}}diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swiftindex c1309066..4f33ed90 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swift@@ -157,7 +157,7 @@ enum PreferenceCleanup {}private static func isOwned(_ name: String, by owner: String?) -> Bool {- guard let owner, Identifier.isReverseDNS(owner) else { return false }+ guard let owner, Identifier.isValid(owner) else { return false }return name == owner || name.hasPrefix(owner + ".")}}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swiftindex d092ffc2..8ed9ae9d 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift@@ -348,6 +348,21 @@ struct LeftoverMatcherTests {#expect(match("com.example.game", in: .caches, for: carrier)?.confidence == .certain)}+ /// A real identifier can have two components or a first one longer than a country or a company's short domain:+ /// Arc is `company.thebrowser.Browser`, Obsidian `md.obsidian`, Notion `notion.id`. A file named exactly by one is+ /// that app's, as certain as any, and so is one named by an identifier it embeds.+ @Test func anIdentifierOfAnyValidShapeProvesItsOwnFiles() throws {+ for (identifier, name) in [("company.thebrowser.Browser", "Arc"), ("md.obsidian", "Obsidian"), ("notion.id", "Notion")] {+ let owned = try #require(match("\(identifier).plist", in: .preferences, for: app(identifier, name: name)))+ #expect(owned.reason == .bundleIdentifier, "\(identifier)")+ #expect(owned.confidence == .certain, "\(identifier)")+ }+ let arc = app("company.thebrowser.Browser", name: "Arc", embedded: ["company.thebrowser.browser.helper"])+ let helper = try #require(match("company.thebrowser.browser.helper", in: .caches, for: arc))+ #expect(helper.reason == .embeddedBundleIdentifier)+ #expect(helper.confidence == .certain)+ }+/// When one app claims an item by name and another by identifier, neither claim wins, whatever their ranks.@Test func aNameAndAnIdentifierThatBothClaimAnItemShareIt() throws {let target = app("com.example.notes", name: "Notes Pro")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swiftindex f80b83d1..f62e2f53 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift@@ -153,6 +153,17 @@ struct RemovalHygieneTests {#expect(PreferenceCleanup.domains(for: [own], ownedBy: "com.someone.else", home: home).isEmpty)}+ /// A sandboxed app whose identifier has two components owns the settings file in its container just the same.+ @Test func forgetsTheDomainOfASandboxedAppWithATwoPartIdentifier() throws {+ let directory = try TemporaryDirectory()+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)+ let own = try directory.file("home/Library/Containers/md.example/Data/Library/Preferences/md.example.plist")++ #expect(PreferenceCleanup.domains(for: [own], ownedBy: "md.example", home: home) == [+ PreferenceCleanup.Domain(name: "md.example", isByHost: false),+ ])+ }+/// A container that cannot be read may hold the settings, so the domain is left alone.@Test func keepsTheDomainOfAContainerItCannotRead() throws {let directory = try TemporaryDirectory()@@ -354,6 +365,29 @@ struct RemovalHygieneTests {#expect(PreferenceBackup.copies(in: backups).map(\.folder.lastPathComponent).count == 2)}+ /// Arc's identifier is `company.thebrowser.Browser` and Obsidian's `md.obsidian`. A copy of their settings is+ /// made, and read back, like any other app's: without it a reset clears nothing.+ @Test func savesTheSettingsOfAnyAppWithAValidIdentifier() async throws {+ let directory = try TemporaryDirectory()+ let backups = try directory.directory("Backups")+ let exporting: PreferenceBackup.Run = { arguments in+ if arguments.first == "export", let file = arguments.last {+ FileManager.default.createFile(atPath: file, contents: Data())+ }+ return .yes+ }+ for identifier in ["company.thebrowser.Browser", "md.obsidian"] {+ let app = InstalledApp(url: URL(filePath: "/Applications/\(identifier).app"), bundleIdentifier: identifier, name: identifier)+ let plist = URL.homeDirectory.appending(path: "Library/Preferences/\(identifier).plist")+ let saved = await PreferenceBackup.save([plist], for: app, in: backups, through: Self.service, run: exporting)+ guard case .saved = saved else {+ Issue.record("no copy of \(identifier)'s settings: \(saved)")+ continue+ }+ }+ #expect(Set(PreferenceBackup.copies(in: backups).map(\.bundleIdentifier)) == ["company.thebrowser.Browser", "md.obsidian"])+ }+/// Settings lists the saved copies, newest first, to put back or clear. A copy may hold a license key.@Test func listsTheCopiesThatWereSaved() throws {let directory = try TemporaryDirectory()