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
Let Remove Peel go on where the Homebrew Peel doesn't run holds no Peel
Țugui Dragoș8d1d6055929d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 52322eec..8298a01d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -271,8 +271,8 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.- `peel exclusions` notes a path that isn't there yet and counts only what went on the list.- A `brew` chosen in Settings that can't be run is never replaced by another, and a `brew` where Homebrew installsitself is run only by the chosen one's rule.-- Remove Peel says why it waits when Homebrew can't answer or Peel doesn't run the Homebrew on this Mac, which may- have installed it, with Open Homebrew, and nothing else moves while Peel removes itself.+- Remove Peel says why it waits when Homebrew can't answer, or when a Homebrew on this Mac that Peel doesn't run+ holds Peel's cask, with Open Homebrew, and nothing else moves while Peel removes itself.#### Applicationsdiff --git a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swiftindex 8b6c294f..9b8c8d25 100644--- a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift+++ b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift@@ -561,6 +561,25 @@ public enum Homebrew {return usualPlaces.first { HomebrewChoice.refusal(of: $0, user: user) == nil }}+ /// Peel's own cask, so named in Homebrew's casks and in its maker's tap.+ static let peelsCask = "peel"++ /// Whether a Homebrew Peel doesn't run may have installed Peel, read without running anything: Peel's cask is in+ /// the Caskroom of the `brew` chosen in Settings or of either place Homebrew installs itself, or one of those+ /// can't be looked into.+ public static func mayHaveInstalledPeel(+ chosen: URL? = HomebrewChoice().load(), root: URL = URL(filePath: "/", directoryHint: .isDirectory)+ ) -> Bool {+ let chosenPrefix = chosen.map { $0.deletingLastPathComponent().deletingLastPathComponent() }+ let prefixes = [chosenPrefix].compactMap(\.self)+ + usualPrefixes.map { root.appending(path: $0, directoryHint: .isDirectory) }+ return prefixes.contains { prefix in+ var info = stat()+ let cask = prefix.appending(path: "Caskroom/\(peelsCask)").path(percentEncoded: false)+ return lstat(cask, &info) == 0 || errno != ENOENT && errno != ENOTDIR+ }+ }+/// The `brew` in a usual place that Peel won't run, and why, when none was chosen and none there can run.public static func refusedInAUsualPlace() -> HomebrewChoice.Unrunnable? {refusedInAUsualPlace(chosen: HomebrewChoice().load(), usualPlaces: usualPlaces)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewChoiceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewChoiceTests.swiftindex 191ad31d..0810486e 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewChoiceTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewChoiceTests.swift@@ -63,6 +63,26 @@ struct HomebrewChoiceTests {#expect(Homebrew.refusedInAUsualPlace(chosen: brew, usualPlaces: [missing, brew], user: getuid() + 1) == nil)}+ @Test(.permissionsHold) func tellsFromItsCaskroomsWhetherAHomebrewMayHaveInstalledPeel() throws {+ let directory = try TemporaryDirectory()+ try directory.directory("opt/homebrew/Caskroom/another-app")+ #expect(!Homebrew.mayHaveInstalledPeel(chosen: nil, root: directory.url))++ let chosen = directory.url.appending(path: "opt/brew/bin/brew")+ try directory.directory("opt/brew/Caskroom/peel")+ #expect(Homebrew.mayHaveInstalledPeel(chosen: chosen, root: directory.url))+ #expect(!Homebrew.mayHaveInstalledPeel(chosen: nil, root: directory.url))++ try directory.directory("usr/local/Caskroom/peel")+ #expect(Homebrew.mayHaveInstalledPeel(chosen: nil, root: directory.url))++ let closed = try TemporaryDirectory()+ try closed.directory("opt/homebrew/Caskroom")+ try closed.setPermissions(0o000, of: "opt/homebrew/Caskroom")+ defer { try? closed.setPermissions(0o755, of: "opt/homebrew/Caskroom") }+ #expect(Homebrew.mayHaveInstalledPeel(chosen: nil, root: closed.url), "a Caskroom it can't look into")+ }+@Test func runsTheChosenBrewAndFindsItsOwnPrograms() throws {let directory = try TemporaryDirectory()let brew = try program("opt/brew/bin/brew", in: directory)diff --git a/Peel/Model/HomebrewLibrary.swift b/Peel/Model/HomebrewLibrary.swiftindex 35999efe..a905b5a5 100644--- a/Peel/Model/HomebrewLibrary.swift+++ b/Peel/Model/HomebrewLibrary.swift@@ -116,6 +116,19 @@ final class HomebrewLibrary {hasAnswered || (!isInstalled && !isNotRun)}+ /// Whether Homebrew says whether it installed this copy of Peel: as it says it of any app, or, while Peel doesn't+ /// run the Homebrew on this Mac, once no Caskroom Peel knows holds Peel's cask.+ var knowsWhetherItInstalledPeel: Bool {+ Self.knowsWhetherItInstalledPeel(+ knowsItsOwnApps: knowsItsOwnApps, isNotRun: isNotRun,+ mayHaveInstalledPeel: isNotRun && Homebrew.mayHaveInstalledPeel()+ )+ }++ static func knowsWhetherItInstalledPeel(knowsItsOwnApps: Bool, isNotRun: Bool, mayHaveInstalledPeel: Bool) -> Bool {+ knowsItsOwnApps || isNotRun && !mayHaveInstalledPeel+ }+static func unanswered(isInstalled: Bool, hasAnswered: Bool, couldNotRead: Bool, needsDefinitions: Bool, isNotRun: Bool) -> Unanswered? {diff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swiftindex 71e047ba..eb7234d4 100644--- a/Peel/Views/Settings/SettingsView.swift+++ b/Peel/Views/Settings/SettingsView.swift@@ -414,7 +414,9 @@ private struct GeneralSettingsView: View {Section {let way = SelfUninstall.way(- cask: ownCask, homebrewKnowsItsApps: homebrew.knowsItsOwnApps, unanswered: homebrew.unanswered+ cask: ownCask,+ homebrewKnowsItsApps: homebrew.knowsWhetherItInstalledPeel,+ unanswered: homebrew.unanswered)if case .homebrew(let command) = way {LabeledContent {diff --git a/PeelTests/SelfUninstallWayTests.swift b/PeelTests/SelfUninstallWayTests.swiftindex 7a8f3220..e0cb955c 100644--- a/PeelTests/SelfUninstallWayTests.swift+++ b/PeelTests/SelfUninstallWayTests.swift@@ -38,4 +38,15 @@ struct SelfUninstallWayTests {let way = SelfUninstall.way(cask: nil, homebrewKnowsItsApps: false, unanswered: .notRun)#expect(way == .homebrewDidNotAnswer(.notRun))}++ @Test func removesPeelWhereNoHomebrewPeelDoesNotRunHoldsPeel() {+ let knows = { (mayHaveInstalledPeel: Bool) in+ HomebrewLibrary.knowsWhetherItInstalledPeel(+ knowsItsOwnApps: false, isNotRun: true, mayHaveInstalledPeel: mayHaveInstalledPeel+ )+ }+ #expect(knows(false))+ #expect(!knows(true))+ #expect(SelfUninstall.way(cask: nil, homebrewKnowsItsApps: knows(false), unanswered: .notRun) == .removePeel)+ }}