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.

Take the links Homebrew made into an app's receipt along with it

Țugui Dragoș2bba4f12c632
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 5f6c8bb8..326a53cc 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -64204,6 +64204,112 @@
}
}
},
+ "Leads into the app’s Homebrew receipt" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Vede do záznamu Homebrew o instalaci aplikace"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Verweist in die Homebrew-Quittung der App"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Lleva al recibo de Homebrew de la app"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Mène dans le reçu Homebrew de l’app"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Punta all’interno della ricevuta Homebrew dell’app"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "アプリのHomebrewレシート内へのリンク"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "앱의 Homebrew 수신 정보로 연결됨"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Leidt naar het Homebrew-installatiebewijs van de app"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Prowadzi do potwierdzenia instalacji aplikacji przez Homebrew"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Aponta para o recibo do app no Homebrew"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Duce în recipisa Homebrew a aplicației"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ведет в квитанцию Homebrew для приложения"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Leder in i appens Homebrew-kvitto"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Uygulamanın Homebrew makbuzunun içindeki bir öğeyi gösteriyor"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Веде до квитанції Homebrew для програми"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "指向App的Homebrew回执内"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "指向App的Homebrew收據內"
+ }
+ }
+ }
+ },
"Leads to a tool inside the app" : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index eac945e1..e4231f35 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -272,6 +272,7 @@ extension MatchReason {
case .nativeMessagingHost: "lets a browser extension run the app"
case .installerReceipt: "installer receipt"
case .homebrewReceipt: "Homebrew receipt"
+ case .leadsIntoItsHomebrewReceipt: "leads into the Homebrew receipt"
case .homebrewCask: "Homebrew cask"
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
index d1191810..0cabe68c 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
@@ -19,6 +19,8 @@ public enum MatchReason: String, Sendable, Hashable {
case installerReceipt
/// The folder of the Homebrew cask that installed the app, which keeps Homebrew counting it as installed.
case homebrewReceipt
+ /// A link Homebrew made that leads into that folder, such as the command it puts on the path.
+ case leadsIntoItsHomebrewReceipt
/// The app's Homebrew cask lists this path in its uninstall or zap stanza.
case homebrewCask
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
index 28afbb6a..fc3d6393 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
@@ -203,7 +203,8 @@ extension LeftoverMatcher {
rank = Self.tier(of: reason) * 10_000 + specificity
family = switch reason {
case .bundleIdentifier, .embeddedBundleIdentifier, .applicationGroup, .bundleIdentifierPrefix,
- .launchdJob, .linksToTheApp, .nativeMessagingHost, .installerReceipt, .homebrewReceipt:
+ .launchdJob, .linksToTheApp, .nativeMessagingHost, .installerReceipt, .homebrewReceipt,
+ .leadsIntoItsHomebrewReceipt:
.identifier
case .name, .namePrefix, .homebrewCask: .name
case .teamIdentifier, .vendorPrefix: .maker
@@ -224,7 +225,7 @@ extension LeftoverMatcher {
switch reason {
// A job's or a manifest's program, or a link's target, lies inside the app's bundle, which no other app
// can share.
- case .launchdJob, .linksToTheApp, .nativeMessagingHost: 8
+ case .launchdJob, .linksToTheApp, .nativeMessagingHost, .leadsIntoItsHomebrewReceipt: 8
case .bundleIdentifier, .installerReceipt, .homebrewReceipt: 7
case .embeddedBundleIdentifier, .applicationGroup: 6
case .bundleIdentifierPrefix: 5
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
index bd0624fa..745a31f6 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
@@ -118,7 +118,8 @@ public struct Uninstallation: Sendable {
}
/// The folder of the cask Homebrew installed the app from, which keeps Homebrew counting the app as installed once
- /// it is gone, and which `brew uninstall` would delete for good. Another app of the cask still in place shares it.
+ /// it is gone, and which `brew uninstall` would delete for good, with the links Homebrew made into it. Another app
+ /// of the cask still in place shares them.
static func homebrewReceipt(
of app: InstalledApp,
casks: [HomebrewPackage],
@@ -142,14 +143,40 @@ public struct Uninstallation: Sendable {
}
return installed?.bundleIdentifier ?? Bundle(url: URL(filePath: target))?.bundleIdentifier ?? target
}
+ let home = environment.homeDirectory.path(percentEncoded: false)
let leftover = await LeftoverScanner.leftover(
at: folder,
kind: .homebrewReceipt,
match: LeftoverMatch(reason: .homebrewReceipt, confidence: .certain, sharedWith: sharedWith.sorted()),
parent: ParentAccess(folder.deletingLastPathComponent()),
- home: environment.homeDirectory.path(percentEncoded: false)
+ home: home
)
- return [exclusions.holds(folder) ? leftover.heldBack(.holdsAnExclusion) : leftover]
+ var leftovers = [exclusions.holds(folder) ? leftover.heldBack(.holdsAnExclusion) : leftover]
+ let receipt = PathPattern.comparablePath(of: folder)
+ for location in environment.locations where location.kind.isForLinks {
+ for link in Self.links(in: location.url, leadingInto: receipt) where !exclusions.excludes(link) {
+ leftovers.append(await LeftoverScanner.leftover(
+ at: link,
+ kind: location.kind,
+ match: LeftoverMatch(
+ reason: .leadsIntoItsHomebrewReceipt, confidence: .certain, sharedWith: sharedWith.sorted()
+ ),
+ parent: ParentAccess(location.url),
+ home: home
+ ))
+ }
+ }
+ return leftovers
+ }
+
+ private static func links(in folder: URL, leadingInto destination: String) -> [URL] {
+ let names = (try? FileManager.default.contentsOfDirectory(atPath: folder.path(percentEncoded: false))) ?? []
+ return names.sorted().map { folder.appending(path: $0) }.filter { link in
+ let path = link.path(percentEncoded: false)
+ guard let target = try? FileManager.default.destinationOfSymbolicLink(atPath: path) else { return false }
+ let resolved = URL(filePath: target, relativeTo: folder).standardizedFileURL
+ return PathComponents.isPath(PathPattern.comparablePath(of: resolved), inside: destination)
+ }
}
/// Leftovers for the paths a cask names (`LeftoverScan.adding` drops those the scanner already found).
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewReceiptTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewReceiptTests.swift
index 68910e43..1546219d 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewReceiptTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewReceiptTests.swift
@@ -67,7 +67,7 @@ struct HomebrewReceiptTests {
func service() throws -> TrashService {
let trash = try directory.directory("home/.Trash")
return TrashService(environment: environment) { url in
- let destination = trash.appending(path: url.lastPathComponent)
+ let destination = trash.appending(path: UUID().uuidString + " " + url.lastPathComponent)
try FileManager.default.moveItem(at: url, to: destination)
return destination
}
@@ -150,4 +150,52 @@ struct HomebrewReceiptTests {
#expect(result.failures.isEmpty, "\(result.failures.map(\.reason))")
#expect(result.trashed.last?.originalURL.lastPathComponent == "example")
}
+
+ @Test func aLinkIntoTheReceiptGoesWithIt() async throws {
+ let installed = try Installed()
+ let app = try installed.app("Example", identifier: "org.example.app")
+ let wrapper = try installed.directory.file("root/opt/homebrew/Caskroom/example/1.0/.homebrew-command-wrappers/example")
+ let bin = try installed.directory.directory("root/opt/homebrew/bin")
+ let command = bin.appending(path: "example")
+ let elsewhere = bin.appending(path: "tool")
+ try FileManager.default.createSymbolicLink(at: command, withDestinationURL: wrapper)
+ try FileManager.default.createSymbolicLink(
+ at: elsewhere, withDestinationURL: try installed.directory.file("root/opt/homebrew/Cellar/tool/1.0/bin/tool")
+ )
+
+ let plan = await Uninstallation.prepare(
+ app, installedApps: [app], casks: [installed.cask(installing: [app])], environment: installed.environment
+ )
+
+ let link = try #require(plan.scan.leftovers.first {
+ $0.url.lastPathComponent == "example" && $0.kind == .commandLineTools
+ })
+ #expect(link.match.reason == .leadsIntoItsHomebrewReceipt)
+ #expect(link.match.isRecommended)
+ #expect(!plan.scan.leftovers.contains { $0.url.lastPathComponent == "tool" })
+ let result = await plan.move(plan.suggestedSelection(canUseHelper: false), using: try installed.service())
+ #expect(result.failures.isEmpty, "\(result.failures.map(\.reason))")
+ #expect(result.trashed.first?.originalURL == app.url)
+ #expect(Set(result.trashed.map(\.originalURL.lastPathComponent)).isSuperset(of: ["example", "Example.app"]))
+ }
+
+ @Test func aLinkIntoASharedReceiptStaysWithIt() async throws {
+ let installed = try Installed()
+ let app = try installed.app("Example", identifier: "org.example.app")
+ let other = try installed.app("Example Helper", identifier: "org.example.helper")
+ let wrapper = try installed.directory.file("root/opt/homebrew/Caskroom/example/1.0/.homebrew-command-wrappers/example")
+ let command = try installed.directory.directory("root/opt/homebrew/bin").appending(path: "example")
+ try FileManager.default.createSymbolicLink(at: command, withDestinationURL: wrapper)
+
+ let plan = await Uninstallation.prepare(
+ app,
+ installedApps: [app, other],
+ casks: [installed.cask(installing: [app, other])],
+ environment: installed.environment
+ )
+
+ let link = try #require(plan.scan.leftovers.first { $0.match.reason == .leadsIntoItsHomebrewReceipt })
+ #expect(link.match.sharedWith == ["org.example.helper"])
+ #expect(!plan.suggestedSelection(canUseHelper: false).contains(link.url))
+ }
}
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index 83597f1f..b458ccc2 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -17,6 +17,7 @@ extension MatchReason {
case .nativeMessagingHost: "Lets a browser extension run a program inside the app"
case .installerReceipt: "The app’s installer receipt"
case .homebrewReceipt: "The app’s Homebrew receipt"
+ case .leadsIntoItsHomebrewReceipt: "Leads into the app’s Homebrew receipt"
case .homebrewCask: "Listed by the Homebrew cask"
}
}
diff --git a/SAFETY.md b/SAFETY.md
index 2c4db861..d5c38b85 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -123,12 +123,12 @@ Peel never deletes anything of yours. Everything it removes goes to the Trash, a
History can put it back; History keeps the most recent 20,000 items, and what it forgets is still in the Trash.
That includes an installer receipt you ask Peel to forget: the two files that make it up go to the Trash
through the helper, where `pkgutil --forget` would have discarded them for good. So does the folder Homebrew keeps
-for an app it installed (`brew --caskroom`), which `brew uninstall` would delete: it goes after the app,
-Homebrew stops listing the app, and History puts both back. Quitting Peel waits for a removal until History has
-it, `peel` carries on through Ctrl-C or a closed terminal until it has written History, and each item is written
-down the moment it moves, so one cut short by a crash or Force Quit still reaches History, as an interrupted
-removal, the next time Peel or `peel` opens it. The space is freed when *you* empty the Trash: Peel never does
-that for you.
+for an app it installed (`brew --caskroom`), with the links Homebrew made into it, which `brew uninstall` would
+delete: they go after the app, Homebrew stops listing the app, and History puts them back. Quitting Peel waits for
+a removal until History has it, `peel` carries on through Ctrl-C or a closed terminal until it has written
+History, and each item is written down the moment it moves, so one cut short by a crash or Force Quit still
+reaches History, as an interrupted removal, the next time Peel or `peel` opens it. The space is freed when *you*
+empty the Trash: Peel never does that for you.
Right before anything moves, Peel looks at the files other programs of yours hold open and at the program each
process runs, and leaves where it is any file or folder with one of them inside, naming the program: moving a