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.

Run no Homebrew cleanup while Peel can't read the Cellar

Țugui Dragoșfebddf324e27
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 65de5bfa..f5f00f5f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -210,6 +210,12 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.
page it selected on when no page is open, so what it selected shows, with Move to Trash, rather than nothing changing
until a page is chosen.
+#### Homebrew
+
+- Clean Up, the download cleanups, and Uninstall run nothing while Peel can't read Homebrew's Cellar, or a formula's
+ folder in it, and say so: Homebrew deletes old versions for good, and Peel couldn't tell it which formulae your
+ exclusions cover.
+
#### Space
- App Caches no longer selects what macOS keeps there for itself under a plain name, such as the picture of your Apple
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 526d6aa7..cef69470 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -109742,6 +109742,112 @@
}
}
},
+ "Peel couldn’t read Homebrew’s Cellar to tell which formulae your exclusions cover, so it ran nothing." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemohl přečíst složku Cellar v Homebrew, aby zjistil, na které formulae se vztahují vaše výjimky, a proto nic nespustil."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel konnte den Cellar von Homebrew nicht lesen, um zu erkennen, welche Formulae unter deine Ausschlüsse fallen, und hat daher nichts ausgeführt."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no ha podido leer el Cellar de Homebrew para saber qué formulae cubren tus exclusiones, así que no ha ejecutado nada."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel n’a pas pu lire le dossier Cellar de Homebrew pour savoir quelles formulae sont concernées par vos exclusions : Peel n’a donc rien exécuté."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non è riuscito a leggere la cartella Cellar di Homebrew per capire quali sono le formulae coperte dalle tue esclusioni, quindi non ha eseguito nulla."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelは、HomebrewのCellarを読み取れず、除外リストに含まれるformulaeを特定できなかったため、何も実行しませんでした。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel은 제외 항목에 포함된 formulae를 확인하는 데 필요한 Homebrew의 Cellar를 읽을 수 없어 아무것도 실행하지 않았습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kon de Cellar van Homebrew niet lezen om na te gaan welke formulae onder je uitsluitingen vallen, en heeft daarom niets uitgevoerd."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie mógł odczytać folderu Cellar w Homebrew, aby ustalić, które formulae są objęte Twoimi wykluczeniami, więc niczego nie uruchomił."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não conseguiu ler a pasta Cellar do Homebrew para identificar as formulae cobertas pelas suas exclusões, então não executou nada."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu a putut citi dosarul Cellar al Homebrew pentru a afla ce formule sunt acoperite de excluderile dvs., așa că nu a rulat nimic."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не удалось прочитать папку Cellar Homebrew, чтобы определить, на какие formulae распространяются Ваши исключения, поэтому ничего не было запущено."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kunde inte läsa Homebrews Cellar för att avgöra vilka formulae som dina undantag omfattar, så Peel körde ingenting."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel, hariç tutulanlarınızın kapsamında hangi formulae olduğunu anlamak için Homebrew’un Cellar klasörünü okuyamadı, bu yüzden hiçbir şey çalıştırmadı."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не вдалося прочитати папку Cellar Homebrew, щоб визначити, які formulae є у ваших винятках, тож Peel нічого не запускала."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel未能读取Homebrew的Cellar以判断哪些是你的排除项所涵盖的formulae,因此没有运行任何命令。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel無法讀取Homebrew的Cellar以判斷哪些是你的排除項目所涵蓋的formulae,因此未執行任何Homebrew指令。"
+ }
+ }
+ }
+ },
"Peel couldn’t read its own files." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift b/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
index b5ca6da7..7eeb8fa0 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
@@ -284,16 +284,24 @@ public struct Exclusions: Sendable, Codable, Hashable {
/// The installed formulae whose own folder under `prefix` is excluded or holds something excluded, which
/// Homebrew is told to keep: `brew cleanup`, and the autoremove `brew uninstall` runs, delete formulae and their
- /// old versions for good. An unreadable list, or one not read yet, keeps every formula.
- public func keptFormulae(inCellarOf prefix: URL) -> [String] {
+ /// old versions for good. An unreadable list, or one not read yet, keeps every formula. Nil when the Cellar, or a
+ /// formula's folder in it, can't be looked into.
+ public func keptFormulae(inCellarOf prefix: URL) -> [String]? {
let cellar = prefix.appending(path: "Cellar", directoryHint: .isDirectory)
- let names = (try? FileManager.default.contentsOfDirectory(atPath: cellar.path(percentEncoded: false))) ?? []
- return names.filter { name in
- guard !name.hasPrefix(".") else { return false }
- guard isKnown else { return true }
+ guard let names = ProtectedData.names(in: cellar.path(percentEncoded: false), followingLinks: true) else {
+ return nil
+ }
+ var kept: [String] = []
+ for name in names.sorted() where !name.hasPrefix(".") {
let own = cellar.appending(path: name, directoryHint: .isDirectory)
- return excludes(own) || holds(own)
- }.sorted()
+ guard isKnown, !excludes(own) else {
+ kept.append(name)
+ continue
+ }
+ guard let holds = holdsSomething(own) else { return nil }
+ if holds { kept.append(name) }
+ }
+ return kept
}
public func keeping<T>(_ items: [T], url: (T) -> URL) -> [T] {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift
index fae1b2a0..8add9e89 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift
@@ -101,6 +101,26 @@ struct HomebrewTests {
/// `brew cleanup` and the autoremove that `brew uninstall` runs delete formulae and their old versions for good,
/// so the formulae the exclusions cover are named in `HOMEBREW_NO_CLEANUP_FORMULAE`, which Homebrew's own
/// documentation says makes it refuse to clean up or autoremove them.
+ /// A formula Peel can't look at may be one the exclusions cover, so nothing that deletes for good runs then.
+ @Test(.permissionsHold) func keepsNoListItCannotReadWhole() throws {
+ let directory = try TemporaryDirectory()
+ try directory.directory("Cellar/wget/1.25.0")
+ try directory.directory("Cellar/jq/1.8.1/kept/org.example.excluded")
+ let excludingWget = Exclusions(paths: [directory.url.appending(path: "Cellar/wget")])
+ let excludingAnApp = Exclusions(bundleIdentifiers: ["org.example.excluded"])
+ defer {
+ try? directory.setPermissions(0o755, of: "Cellar")
+ try? directory.setPermissions(0o755, of: "Cellar/jq/1.8.1")
+ }
+
+ try directory.setPermissions(0, of: "Cellar")
+ #expect(excludingWget.keptFormulae(inCellarOf: directory.url) == nil)
+ try directory.setPermissions(0o755, of: "Cellar")
+ try directory.setPermissions(0, of: "Cellar/jq/1.8.1")
+ #expect(excludingAnApp.keptFormulae(inCellarOf: directory.url) == nil)
+ #expect(excludingWget.keptFormulae(inCellarOf: directory.url.appending(path: "Missing")) == [])
+ }
+
@Test func homebrewIsToldToKeepTheFormulaeTheExclusionsCover() async throws {
let directory = try TemporaryDirectory()
try directory.directory("Cellar/wget/1.25.0")
@@ -110,7 +130,7 @@ struct HomebrewTests {
directory.url.appending(path: "Cellar/jq"), directory.url.appending(path: "Cellar/[email protected]/3.13.7"),
])
- let kept = exclusions.keptFormulae(inCellarOf: directory.url)
+ let kept = try #require(exclusions.keptFormulae(inCellarOf: directory.url))
#expect(kept == ["jq", "[email protected]"])
#expect(Exclusions.unreadable.keptFormulae(inCellarOf: directory.url) == ["jq", "[email protected]", "wget"])
diff --git a/Peel/Model/HomebrewLibrary.swift b/Peel/Model/HomebrewLibrary.swift
index dd951bfe..351eadcf 100644
--- a/Peel/Model/HomebrewLibrary.swift
+++ b/Peel/Model/HomebrewLibrary.swift
@@ -44,6 +44,14 @@ final class HomebrewLibrary {
.vulnerabilities: false
}
}
+
+ /// Whether Homebrew deletes formulae for good while it runs, which it does keeping the ones Peel names.
+ var deletesFormulae: Bool {
+ switch self {
+ case .uninstall, .cleanup, .clearOlderDownloads, .clearEveryDownload: true
+ case .upgrade, .upgradeAll, .update, .repairTaps, .health, .vulnerabilities: false
+ }
+ }
}
struct CommandResult: Identifiable {
@@ -261,7 +269,7 @@ final class HomebrewLibrary {
// The installation is read first, since it says how to read the figures that follow. The other questions
// take about as long as each other, so they run at the same time. Only the page shows the last two.
let found = await Homebrew.installation()
- let kept = found.map { ExclusionsStore.shared.exclusions.keptFormulae(inCellarOf: $0.prefix) } ?? []
+ let kept = found.flatMap { ExclusionsStore.shared.exclusions.keptFormulae(inCellarOf: $0.prefix) } ?? []
async let preview = includingReclaimable ? Homebrew.cleanupPreview(asWrittenBy: found, keeping: kept) : nil
async let overridden = includingReclaimable ? Homebrew.overrides() : nil
let installed: Result<[HomebrewPackage], Homebrew.CommandFailure>
@@ -332,6 +340,13 @@ final class HomebrewLibrary {
if command.isUpgrade, await cleansUpAfterUpgrading() {
return CommandResult(succeeded: false, output: String(localized: Self.cleansUp))
}
+ var kept: [String] = []
+ if command.deletesFormulae {
+ switch await keptFormulae() {
+ case .formulae(let formulae): kept = formulae
+ case .nothingRuns(let result): return result
+ }
+ }
do {
let output: String
switch command {
@@ -347,18 +362,14 @@ final class HomebrewLibrary {
}
case .uninstall(let id):
guard let package = package(id) else { return gone }
- guard let kept = await keptFormulae() else { return keepsNothing }
output = try await Homebrew.uninstall(package, keeping: kept)
case .update:
output = try await Homebrew.updateMetadata()
case .cleanup:
- guard let kept = await keptFormulae() else { return keepsNothing }
output = try await Homebrew.cleanup(keeping: kept)
case .clearOlderDownloads:
- guard let kept = await keptFormulae() else { return keepsNothing }
output = try await Homebrew.cleanup(.olderThan(days: 30), keeping: kept)
case .clearEveryDownload:
- guard let kept = await keptFormulae() else { return keepsNothing }
output = try await Homebrew.cleanup(.everyDownload, keeping: kept)
case .repairTaps:
output = try await Homebrew.repairTaps()
@@ -393,12 +404,20 @@ final class HomebrewLibrary {
CommandResult(succeeded: false, output: String(localized: "Peel couldn’t make sure Homebrew keeps the formulae your exclusions cover, so it ran nothing. A brew.env file that sets HOMEBREW_NO_CLEANUP_FORMULAE replaces the list Peel gives it."))
}
+ /// The formulae Homebrew is told to keep, or what Peel says when it runs nothing.
+ private enum Keeping {
+ case formulae([String])
+ case nothingRuns(CommandResult)
+ }
+
/// The formulae the exclusions cover, which Homebrew is told to keep, asked again right before a command that
- /// deletes for good. Nil when Peel can't tell which they are or Homebrew's own settings replace the list.
- private func keptFormulae() async -> [String]? {
- guard let prefix = installation?.prefix else { return nil }
- let kept = ExclusionsStore.shared.exclusions.keptFormulae(inCellarOf: prefix)
- return await Homebrew.keepsEvery(kept) ? kept : nil
+ /// deletes for good. Nothing runs when Peel can't tell which they are or Homebrew's own settings replace the list.
+ private func keptFormulae() async -> Keeping {
+ guard let prefix = installation?.prefix else { return .nothingRuns(keepsNothing) }
+ guard let kept = ExclusionsStore.shared.exclusions.keptFormulae(inCellarOf: prefix) else {
+ return .nothingRuns(CommandResult(succeeded: false, output: String(localized: "Peel couldn’t read Homebrew’s Cellar to tell which formulae your exclusions cover, so it ran nothing.")))
+ }
+ return await Homebrew.keepsEvery(kept) ? .formulae(kept) : .nothingRuns(keepsNothing)
}
private static func announce(_ words: LocalizedStringResource) {
diff --git a/SAFETY.md b/SAFETY.md
index 91010d3f..bed24da4 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -530,7 +530,8 @@ only by their own paths, so to keep them, exclude them too.
Exclusions reach the Homebrew page too, since Homebrew deletes for good: Peel never runs `brew uninstall` for a
package whose app, or whose own folder, you excluded, nor for one with a folder Peel can't look into for an app you
excluded, nor for any package while your list isn't read or can't be, and Homebrew's cleanup keeps every formula whose
-folder you excluded.
+folder you excluded. While Peel can't read Homebrew's Cellar, or a formula's folder in it, nothing that deletes
+formulae runs at all.
If the saved list is there and cannot be read, Peel does not treat it as empty. It moves nothing until you
start over in Settings, `peel` refuses, and the file it could not read is kept beside the new one.