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.

Never forget the running app's own settings domain

Țugui Dragoș9c2520c3184b
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swift
index b27a3dd7..16a38d2a 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swift
@@ -96,7 +96,8 @@ enum PreferenceCleanup {
for urls: [URL],
ownedBy owner: String? = nil,
home: URL = .homeDirectory,
- host: String = PreferenceCleanup.hostIdentifier
+ host: String = PreferenceCleanup.hostIdentifier,
+ running: String? = Bundle.main.bundleIdentifier
) -> [Domain] {
// Only the user's `Library/Preferences` and its `ByHost` folder, plus the settings file in the container
// of the app being reset. `defaults` reads a name as this user's domain, so a file from
@@ -119,6 +120,9 @@ enum PreferenceCleanup {
|| isTheSettingsFile(name, in: parent, ofTheAppBeingReset: owner, home: home)
else { return nil }
guard isUsableName(name) else { return nil }
+ // Never the running app's own, as when Peel removes itself: while it runs, `defaults delete` makes
+ // cfprefsd write the domain back as an empty file.
+ guard running.map({ name.caseInsensitiveCompare($0) != .orderedSame }) ?? true else { return nil }
// A ByHost file is named `<domain>.<host UUID>.plist`. `-currentHost` always means the current Mac, so
// a file another Mac left behind names no domain here.
let fileHost = url.lastPathComponent.removingSuffix(".plist").dropFirst(name.count + 1)
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift
index 47ffb085..5c36f395 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift
@@ -76,6 +76,17 @@ struct RemovalHygieneTests {
])
}
+ @Test func neverForgetsTheRunningAppsOwnDomain() {
+ let urls = [
+ URL(filePath: "/Users/x/Library/Preferences/com.tuguidragos.Peel.plist"),
+ URL(filePath: "/Users/x/Library/Preferences/com.example.app.plist"),
+ ]
+
+ #expect(PreferenceCleanup.domains(for: urls, home: home, host: host, running: "com.tuguidragos.Peel") == [
+ PreferenceCleanup.Domain(name: "com.example.app", isByHost: false),
+ ])
+ }
+
/// `-currentHost` means the Mac Peel runs on, so a ByHost file another Mac left names no domain.
@Test func forgetsNothingForAByHostFileFromAnotherMac() {
let urls = [