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.

Say before a formula's uninstall what Homebrew leaves of it

Țugui Dragoșc5a98512f2e2
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 15e0b592..51fb17dc 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -63113,6 +63113,112 @@
}
}
},
+ "Homebrew leaves %@, with any data or settings the formula kept there." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew ponechá %@ i se všemi daty nebo nastaveními, která tam formula uchovávala."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew lässt %@ zurück, samt allen Daten oder Einstellungen, die die Formula dort aufbewahrt hat."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew deja %@, con los datos o ajustes que la formula haya guardado ahí."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew laisse en place %@, avec les données ou les réglages que la formula y a éventuellement conservés."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew lascia %@, con gli eventuali dati o le impostazioni che la formula vi ha conservato."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrewは%@を、formulaがそこに保存したデータや設定ごと残します。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew는 %@을(를) 이 formula가 그곳에 보관한 데이터나 설정과 함께 그대로 남겨 둡니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew laat %@ achter, met alle gegevens of instellingen die de formula daar heeft bewaard."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew zostawia %@ wraz ze wszelkimi danymi i ustawieniami, które formula tam przechowywała."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Homebrew mantém %@, com quaisquer dados ou ajustes que a formula tenha guardado ali."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew lasă în urmă %@, împreună cu orice date sau configurări pe care formula le‑a păstrat acolo."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew оставит %@ вместе с данными и настройками, которые formula могла там хранить."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew lämnar kvar %@, med eventuella data eller inställningar som formulan har sparat där."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew, %@ içeriğini, yani bu formula için orada tutulan tüm verileri veya ayarları yerinde bırakır."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew залишить %@ разом з усіма даними й налаштуваннями, які там зберігала formula."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew会保留%@,以及此formula在其中保存的任何数据或设置。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew會留下%@,連同該formula保存在其中的任何資料或設定。"
+ }
+ }
+ }
+ },
"Homebrew may download its list of packages when Peel only asks about them." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Homebrew/FormulaInUse.swift b/Packages/PeelCore/Sources/PeelCore/Homebrew/FormulaInUse.swift
index 97adc7a2..1529e0d8 100644
--- a/Packages/PeelCore/Sources/PeelCore/Homebrew/FormulaInUse.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Homebrew/FormulaInUse.swift
@@ -7,6 +7,10 @@ public struct FormulaInUse: Sendable, Hashable {
public let programs: [String]
/// What stops the job `brew services` keeps for the formula and takes its file away, to run in Terminal.
public let stopCommand: String?
+ /// What Homebrew keeps under the formula's name in its `var` and `etc`, which `brew uninstall` leaves: the data of
+ /// a database, say, or a server's settings. Homebrew warns about its `etc` folder only once it is gone
+ /// (`uninstall.rb`), and says nothing of `var`.
+ public var dataFolders: [URL] = []
public var isEmpty: Bool { programs.isEmpty && stopCommand == nil }
@@ -25,6 +29,11 @@ public struct FormulaInUse: Sendable, Hashable {
: hasAJob(in: root, "LaunchDaemons") ? "sudo brew services stop \(name)"
: nil
let folder = cellar.appending(path: name, directoryHint: .isDirectory)
- return FormulaInUse(programs: OpenFiles().holders(of: folder), stopCommand: stopCommand)
+ let prefix = cellar.deletingLastPathComponent()
+ return FormulaInUse(
+ programs: OpenFiles().holders(of: folder),
+ stopCommand: stopCommand,
+ dataFolders: ["var", "etc"].map { prefix.appending(path: "\($0)/\(name)") }.filter { !$0.isMissing }
+ )
}
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FormulaInUseTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FormulaInUseTests.swift
index 101a895f..ff8d3fe9 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/FormulaInUseTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/FormulaInUseTests.swift
@@ -25,4 +25,24 @@ import Testing
#expect(found("tool@1").stopCommand == "brew services stop tool@1")
#expect(found("other").isEmpty)
}
+
+ @Test func namesWhatAFormulaKeepsInVarAndEtcUnderItsName() throws {
+ let directory = try TemporaryDirectory()
+ let prefix = directory.url.appending(path: "prefix", directoryHint: .isDirectory)
+ let data = try directory.file("prefix/var/tool@1/base/1/PG_VERSION").deletingLastPathComponent()
+ .deletingLastPathComponent().deletingLastPathComponent()
+ let settings = try directory.file("prefix/etc/tool@1/tool.conf").deletingLastPathComponent()
+ try directory.file("prefix/var/tool/base/PG_VERSION")
+ try directory.directory("prefix/Cellar")
+ func found(_ name: String) -> FormulaInUse {
+ FormulaInUse.of(
+ formula: name, cellar: prefix.appending(path: "Cellar"), home: directory.url, root: directory.url
+ )
+ }
+
+ #expect(found("tool@1").dataFolders.map(\.lastPathComponent) == ["tool@1", "tool@1"])
+ #expect(found("tool@1").dataFolders.map { PathPattern.comparablePath(of: $0) }
+ == [data, settings].map { PathPattern.comparablePath(of: $0) })
+ #expect(found("other").dataFolders.isEmpty)
+ }
}
diff --git a/Peel/Views/Homebrew/HomebrewDetailView.swift b/Peel/Views/Homebrew/HomebrewDetailView.swift
index 5bf005eb..67be6ac9 100644
--- a/Peel/Views/Homebrew/HomebrewDetailView.swift
+++ b/Peel/Views/Homebrew/HomebrewDetailView.swift
@@ -290,7 +290,15 @@ struct HomebrewDetailView: View {
let deletes = homebrew.overrides.contains(.keepsDependencies)
? Text("Homebrew deletes the package for good: nothing goes to the Trash, and History can’t put it back. It won’t do this while another package needs it.")
: Text("Homebrew deletes the package for good: nothing goes to the Trash, and History can’t put it back. It won’t do this while another package needs it, and it also removes every formula nothing needs anymore, whichever package brought it in.")
- return whatUsesIt.map { Text("\($0)\n\n\(deletes)") } ?? deletes
+ let deletesAndLeaves = whatStays.map { Text("\(deletes)\n\n\($0)") } ?? deletes
+ return whatUsesIt.map { Text("\($0)\n\n\(deletesAndLeaves)") } ?? deletesAndLeaves
+ }
+
+ /// What Homebrew leaves of a formula, which it says nothing of before it deletes the rest.
+ private var whatStays: Text? {
+ guard let folders = inUse?.dataFolders, !folders.isEmpty else { return nil }
+ let places = folders.map(\.abbreviatedPath).formatted(.list(type: .and))
+ return Text("Homebrew leaves \(places), with any data or settings the formula kept there.")
}
/// What Homebrew won't look at before it deletes a formula, said before it does.