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 which folder stops an account changing Homebrew, and how to get it back

Țugui Dragoșe63bf8a9f734
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index efca9c45..301b518a 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -766,6 +766,230 @@
}
}
},
+ "%@ belongs to root, so Homebrew can’t change it, and Homebrew doesn’t run as root. Give the folder back to this account by running this in Terminal: %@" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Složka %1$@ patří uživateli root, takže ji Homebrew nemůže měnit, a pod uživatelem root Homebrew neběží. Vraťte složku tomuto účtu spuštěním tohoto příkazu v Terminálu: %2$@"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ gehört root, daher kann Homebrew diesen Ordner nicht ändern, und Homebrew läuft nicht als root. Gib den Ordner diesem Benutzeraccount zurück, indem du diesen Befehl im Terminal ausführst: %2$@"
+ }
+ },
+ "en" : {
+ "stringUnit" : {
+ "state" : "new",
+ "value" : "%1$@ belongs to root, so Homebrew can’t change it, and Homebrew doesn’t run as root. Give the folder back to this account by running this in Terminal: %2$@"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ pertenece a root, así que Homebrew no puede modificar esa carpeta, y Homebrew no se ejecuta como root. Devuelve la carpeta a esta cuenta ejecutando esto en Terminal: %2$@"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ appartient à root : Homebrew ne peut donc pas le modifier, et Homebrew ne s’exécute pas en tant que root. Rendez le dossier à ce compte en exécutant ceci dans Terminal : %2$@"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ appartiene a root, quindi Homebrew non può modificarla, e Homebrew non viene eseguito come root. Restituisci la cartella a questo account eseguendo questo comando in Terminale: %2$@"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@はrootが所有しているため、Homebrewは変更できません。また、Homebrewはrootとして実行されません。ターミナルで以下のコマンドを実行して、このフォルダの所有権をこのアカウントに戻してください: %2$@"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@은(는) Root 사용자에게 속해 있으므로 Homebrew가 변경할 수 없으며, Homebrew는 Root 사용자로 실행되지 않습니다. 이 폴더를 이 계정에 되돌려 주려면 터미널에서 다음을 실행하십시오: %2$@"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ is van root, dus Homebrew kan die map niet wijzigen, en Homebrew wordt niet als root uitgevoerd. Geef de map terug aan deze account door dit uit te voeren in Terminal: %2$@"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Folder %1$@ należy do użytkownika root, więc Homebrew nie może go zmieniać, a Homebrew nie działa jako root. Oddaj ten folder temu kontu, uruchamiając w Terminalu to polecenie: %2$@"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "A pasta %1$@ pertence ao root, então o Homebrew não pode alterá-la, e o Homebrew não é executado como root. Devolva a pasta a esta conta executando isto no Terminal: %2$@"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ aparține utilizatorului Root, așa că Homebrew nu îl poate modifica, iar Homebrew nu rulează ca utilizator Root. Dați dosarul înapoi acestui cont rulând această comandă în Terminal: %2$@"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Папка %1$@ принадлежит root, поэтому Homebrew не может ее изменить, а от имени root Homebrew не запускается. Верните папку этой учетной записи, выполнив эту команду в Терминале: %2$@"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ tillhör rotanvändaren, så Homebrew kan inte ändra den, och Homebrew körs inte som rotanvändare. Ge tillbaka mappen till det här kontot genom att köra följande i Terminal: %2$@"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ klasörünün sahibi root, bu yüzden Homebrew onu değiştiremez; Homebrew root olarak da çalışmaz. Terminal’de şunu çalıştırarak klasörü bu hesaba geri verin: %2$@"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Папка %1$@ належить root, тож Homebrew не може її змінювати, а від імені root Homebrew не працює. Поверніть папку цьому обліковому запису, виконавши в Терміналі цю команду: %2$@"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@归root所有,因此Homebrew无法更改它,而Homebrew也不会以root身份运行。请在“终端”中运行以下命令,将该文件夹交还给此账户:%2$@"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@屬於root,因此Homebrew無法更改它,而Homebrew也不會以root身分執行。請在「終端機」中執行此指令,將該檔案夾交還給此帳號:%2$@"
+ }
+ }
+ }
+ },
+ "%@ belongs to this account but can’t be written to, so Homebrew can’t change it. Allow it by running this in Terminal: %@" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Složka %1$@ patří tomuto účtu, ale nelze do ní zapisovat, takže ji Homebrew nemůže měnit. Povolte zápis spuštěním tohoto příkazu v Terminálu: %2$@"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ gehört diesem Benutzeraccount, ist aber schreibgeschützt, daher kann Homebrew diesen Ordner nicht ändern. Erlaube das Schreiben, indem du diesen Befehl im Terminal ausführst: %2$@"
+ }
+ },
+ "en" : {
+ "stringUnit" : {
+ "state" : "new",
+ "value" : "%1$@ belongs to this account but can’t be written to, so Homebrew can’t change it. Allow it by running this in Terminal: %2$@"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ pertenece a esta cuenta, pero no se puede escribir en esa carpeta, así que Homebrew no puede modificarla. Permítelo ejecutando esto en Terminal: %2$@"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ appartient à ce compte, mais il est impossible d’y écrire : Homebrew ne peut donc pas le modifier. Autorisez l’écriture en exécutant ceci dans Terminal : %2$@"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ appartiene a questo account ma non consente la scrittura, quindi Homebrew non può modificarla. Consentila eseguendo questo comando in Terminale: %2$@"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@はこのアカウントが所有していますが、書き込みができないため、Homebrewは変更できません。ターミナルで以下のコマンドを実行して、書き込みを許可してください: %2$@"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@은(는) 이 계정에 속해 있지만 쓸 수 없으므로 Homebrew가 변경할 수 없습니다. 쓰기를 허용하려면 터미널에서 다음을 실행하십시오: %2$@"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ is van deze account, maar er kan niet naar worden geschreven, dus Homebrew kan die map niet wijzigen. Sta het toe door dit uit te voeren in Terminal: %2$@"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Folder %1$@ należy do tego konta, ale nie można w nim zapisywać, więc Homebrew nie może go zmieniać. Pozwól na to, uruchamiając w Terminalu to polecenie: %2$@"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "A pasta %1$@ pertence a esta conta, mas não é possível gravar nela, então o Homebrew não pode alterá-la. Permita a gravação executando isto no Terminal: %2$@"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ aparține acestui cont, dar nu se poate scrie în el, așa că Homebrew nu îl poate modifica. Permiteți scrierea rulând această comandă în Terminal: %2$@"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Папка %1$@ принадлежит этой учетной записи, но запись в нее запрещена, поэтому Homebrew не может ее изменить. Разрешите запись, выполнив эту команду в Терминале: %2$@"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ tillhör det här kontot men går inte att skriva till, så Homebrew kan inte ändra den. Tillåt det genom att köra följande i Terminal: %2$@"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ klasörü bu hesaba ait ancak ona yazılamıyor, bu yüzden Homebrew onu değiştiremez. Terminal’de şunu çalıştırarak yazmaya izin verin: %2$@"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Папка %1$@ належить цьому обліковому запису, але недоступна для запису, тож Homebrew не може її змінювати. Дозвольте запис, виконавши в Терміналі цю команду: %2$@"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@属于此账户,但无法写入,因此Homebrew无法更改它。请在“终端”中运行以下命令以允许写入:%2$@"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@屬於此帳號,但無法寫入,因此Homebrew無法更改它。請在「終端機」中執行此指令以允許寫入:%2$@"
+ }
+ }
+ }
+ },
"%@ came from Setapp. Setapp is what keeps it current, so Peel has nothing to ask." : {
"localizations" : {
"cs" : {
@@ -197687,6 +197911,112 @@
}
}
},
+ "This Account Can’t Change Homebrew" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tento účet nemůže měnit Homebrew"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dieser Benutzeraccount kann Homebrew nicht ändern"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Esta cuenta no puede modificar Homebrew"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ce compte ne peut pas modifier Homebrew"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Questo account non può modificare Homebrew"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "このアカウントではHomebrewを変更できません"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "이 계정은 Homebrew를 변경할 수 없음"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Deze account kan Homebrew niet wijzigen"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "To konto nie może zmieniać Homebrew"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Esta Conta Não Pode Alterar o Homebrew"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Acest cont nu poate modifica Homebrew"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Эта учетная запись не может изменять Homebrew"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Det här kontot kan inte ändra Homebrew"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bu Hesap Homebrew’u Değiştiremez"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Цей обліковий запис не може змінювати Homebrew"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "此账户无法更改Homebrew"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "此帳號無法更改Homebrew"
+ }
+ }
+ }
+ },
"This Belongs To" : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift
index 70ad215d..64b98917 100644
--- a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift
@@ -252,10 +252,34 @@ public struct HomebrewInstallation: Sendable, Hashable {
public let cellar: URL
/// Where Homebrew itself is, as it says: the prefix on a Mac with Apple silicon, `/usr/local/Homebrew` on Intel.
public let repository: URL
- /// The account the repository belongs to, which installed Homebrew.
- public private(set) var owner: String?
- /// Whether this account may change Homebrew (`Homebrew.mayBeChanged`), judged when it was read.
- public private(set) var mayBeChangedByThisAccount = true
+ /// The folder that stops this account changing Homebrew (`Homebrew.unwritableFolder`), judged when it was read.
+ public private(set) var unwritable: Unwritable?
+
+ /// A folder of Homebrew's this account can't write, and whose it is.
+ public struct Unwritable: Sendable, Hashable {
+ public enum Owner: Sendable, Hashable {
+ case thisAccount
+ case root
+ /// Another account of this Mac, by its name where it has one.
+ case another(String?)
+ }
+
+ public let folder: URL
+ public let owner: Owner
+
+ /// What gives this account the folder back in Terminal: Homebrew's own advice (`cmd/update.sh`), or the
+ /// permission it lacks when it is already this account's. Nil for another account's, which is theirs to give.
+ public var command: String? {
+ let path = PathPattern.comparablePath(of: folder).replacingOccurrences(of: "'", with: "'\\''")
+ return switch owner {
+ case .thisAccount: "chmod u+w '\(path)'"
+ case .root: "sudo chown -R $(whoami) '\(path)'"
+ case .another: nil
+ }
+ }
+ }
+
+ public var mayBeChangedByThisAccount: Bool { unwritable == nil }
public var caskroom: URL {
prefix.appending(path: "Caskroom", directoryHint: .isDirectory)
@@ -284,12 +308,18 @@ public struct HomebrewInstallation: Sendable, Hashable {
.compactMap { Int($0) }
}
- /// A copy that says whose Homebrew this is and whether this account may change it.
- func judgedForThisAccount() -> HomebrewInstallation {
+ /// A copy that says whether this account, `user`, may change Homebrew, and if not, which folder stops it.
+ func judgedForThisAccount(user: uid_t = getuid()) -> HomebrewInstallation {
var judged = self
- let path = repository.path(percentEncoded: false)
- judged.owner = (try? FileManager.default.attributesOfItem(atPath: path))?[.ownerAccountName] as? String
- judged.mayBeChangedByThisAccount = Homebrew.mayBeChanged(cellar: cellar, repository: repository)
+ judged.unwritable = Homebrew.unwritableFolder(cellar: cellar, repository: repository).map { folder in
+ let attributes = try? FileManager.default.attributesOfItem(atPath: folder.path(percentEncoded: false))
+ let account = (attributes?[.ownerAccountID] as? NSNumber)?.uint32Value
+ let owner: Unwritable.Owner =
+ account == user ? .thisAccount
+ : account == 0 ? .root
+ : .another(attributes?[.ownerAccountName] as? String)
+ return Unwritable(folder: folder, owner: owner)
+ }
return judged
}
@@ -518,12 +548,12 @@ indirect enum CaskValue: Decodable, Sendable {
public enum Homebrew {
static let notInstalled = "Homebrew isn’t installed."
- /// Whether this account may change the Homebrew whose Cellar and repository these are, as `brew update` judges it
- /// (`cmd/update.sh`): the Cellar, when there is one, and the repository can be written. Homebrew belongs to the
- /// account that installed it, so another account of the Mac can read it and not change it.
- static func mayBeChanged(cellar: URL, repository: URL) -> Bool {
+ /// The folder that stops this account changing the Homebrew whose Cellar and repository these are, as `brew update`
+ /// judges it (`cmd/update.sh`): the Cellar, when there is one, then the repository, each has to be writable.
+ static func unwritableFolder(cellar: URL, repository: URL) -> URL? {
func writable(_ url: URL) -> Bool { access(url.path(percentEncoded: false), W_OK) == 0 }
- return (cellar.isMissing || writable(cellar)) && writable(repository)
+ if !cellar.isMissing, !writable(cellar) { return cellar }
+ return writable(repository) ? nil : repository
}
/// Whether `sudo` stopped for a password it had no terminal to ask in, in its own words, which it writes in English
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift
index e525d5b5..177d5491 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift
@@ -45,20 +45,42 @@ struct HomebrewTests {
#expect(Homebrew.environment(autoUpdate: false, writesLinesAsTheyGo: false)["CI"] == nil)
}
- @Test(.permissionsHold) func knowsWhetherThisAccountMayChangeHomebrew() throws {
+ @Test(.permissionsHold) func knowsWhichFolderStopsThisAccountChangingHomebrew() throws {
let directory = try TemporaryDirectory()
let repository = try directory.directory("homebrew")
let cellar = repository.appending(path: "Cellar", directoryHint: .isDirectory)
- #expect(Homebrew.mayBeChanged(cellar: cellar, repository: repository), "a Cellar not made yet stops nothing")
+ #expect(Homebrew.unwritableFolder(cellar: cellar, repository: repository) == nil, "a Cellar not made yet")
try directory.directory("homebrew/Cellar")
- #expect(Homebrew.mayBeChanged(cellar: cellar, repository: repository))
+ #expect(Homebrew.unwritableFolder(cellar: cellar, repository: repository) == nil)
try directory.setPermissions(0o555, of: cellar)
- #expect(!Homebrew.mayBeChanged(cellar: cellar, repository: repository))
+ #expect(Homebrew.unwritableFolder(cellar: cellar, repository: repository) == cellar)
try directory.setPermissions(0o755, of: cellar)
try directory.setPermissions(0o555, of: repository)
defer { try? directory.setPermissions(0o755, of: repository) }
- #expect(!Homebrew.mayBeChanged(cellar: cellar, repository: repository))
+ #expect(Homebrew.unwritableFolder(cellar: cellar, repository: repository) == repository)
+ }
+
+ @Test(.permissionsHold) func saysWhoseFolderStopsThisAccountAndWhatGivesItBack() throws {
+ let directory = try TemporaryDirectory()
+ let repository = try directory.directory("homebrew")
+ let path = PathPattern.comparablePath(of: repository)
+ let installation = HomebrewInstallation(version: "7.0.0", prefix: repository, repository: repository)
+ #expect(installation.judgedForThisAccount().mayBeChangedByThisAccount)
+ try directory.setPermissions(0o555, of: repository)
+ defer { try? directory.setPermissions(0o755, of: repository) }
+
+ let own = try #require(installation.judgedForThisAccount().unwritable)
+ #expect(own.owner == .thisAccount)
+ #expect(own.command == "chmod u+w '\(path)'")
+ let another = try #require(installation.judgedForThisAccount(user: getuid() + 1).unwritable)
+ #expect(another.owner == .another(NSUserName()))
+ #expect(another.command == nil)
+ let system = URL(filePath: "/usr/share", directoryHint: .isDirectory)
+ let roots = HomebrewInstallation(version: "7.0.0", prefix: system, repository: system)
+ let root = try #require(roots.judgedForThisAccount().unwritable)
+ #expect(root.owner == .root)
+ #expect(root.command == "sudo chown -R $(whoami) '/usr/share'")
}
@Test func aDisabledPackageWaitsForNoUpgrade() {
diff --git a/Peel/Model/HomebrewLibrary.swift b/Peel/Model/HomebrewLibrary.swift
index ce65d2c6..b21ee827 100644
--- a/Peel/Model/HomebrewLibrary.swift
+++ b/Peel/Model/HomebrewLibrary.swift
@@ -170,13 +170,43 @@ final class HomebrewLibrary {
/// lists can be read, and what changes it is left to the account it belongs to.
var mayChange: Bool { installation?.mayBeChangedByThisAccount ?? true }
- /// Why this account can't change Homebrew, or nil when it can.
- var belongsToAnotherAccount: LocalizedStringResource? {
- guard !mayChange else { return nil }
- if let owner = installation?.owner {
- return "Homebrew on this Mac belongs to \(owner), so only that account can update or change it."
+ /// Why this account can't change Homebrew, and the command that puts it right where this account can run one.
+ struct CantChange {
+ let title: LocalizedStringResource
+ let detail: LocalizedStringResource
+ var command: String?
+ }
+
+ /// Nil when this account can change Homebrew. Root can't help, since Homebrew refuses to run as root (`brew.sh`),
+ /// and a folder of this account's own only lacks a permission, so only another account's is theirs to change.
+ var whyItCantChange: CantChange? {
+ guard let unwritable = installation?.unwritable else { return nil }
+ let folder = unwritable.folder.abbreviatedPath
+ let command = unwritable.command ?? ""
+ switch unwritable.owner {
+ case .another(let owner?):
+ return CantChange(
+ title: "Homebrew Belongs to Another Account",
+ detail: "Homebrew on this Mac belongs to \(owner), so only that account can update or change it."
+ )
+ case .another(nil):
+ return CantChange(
+ title: "Homebrew Belongs to Another Account",
+ detail: "Homebrew on this Mac belongs to another account, so only that account can update or change it."
+ )
+ case .root:
+ return CantChange(
+ title: "This Account Can’t Change Homebrew",
+ detail: "\(folder) belongs to root, so Homebrew can’t change it, and Homebrew doesn’t run as root. Give the folder back to this account by running this in Terminal: \(command)",
+ command: command
+ )
+ case .thisAccount:
+ return CantChange(
+ title: "This Account Can’t Change Homebrew",
+ detail: "\(folder) belongs to this account but can’t be written to, so Homebrew can’t change it. Allow it by running this in Terminal: \(command)",
+ command: command
+ )
}
- return "Homebrew on this Mac belongs to another account, so only that account can update or change it."
}
/// Incremented only when the known casks or receipts change, or Homebrew leaves the Mac. An app's page scans
diff --git a/Peel/Views/Homebrew/HomebrewDetailView.swift b/Peel/Views/Homebrew/HomebrewDetailView.swift
index 9bd2bf70..bf3514f0 100644
--- a/Peel/Views/Homebrew/HomebrewDetailView.swift
+++ b/Peel/Views/Homebrew/HomebrewDetailView.swift
@@ -117,10 +117,13 @@ struct HomebrewDetailView: View {
}
Section {
- if let anotherAccount = homebrew.belongsToAnotherAccount {
- Text(anotherAccount)
+ if let reason = homebrew.whyItCantChange {
+ Text(reason.detail)
.font(.callout)
.foregroundStyle(.secondary)
+ if let command = reason.command {
+ CopyButton(text: command)
+ }
} else {
if package.isMissingWhatItInstalled {
RemovalsHeldBanner()
diff --git a/Peel/Views/Homebrew/HomebrewList.swift b/Peel/Views/Homebrew/HomebrewList.swift
index 28f6bded..16b1ee3a 100644
--- a/Peel/Views/Homebrew/HomebrewList.swift
+++ b/Peel/Views/Homebrew/HomebrewList.swift
@@ -36,10 +36,8 @@ struct HomebrewList: View {
}
// While searching, the page lists only the matching packages and hides every other section.
if searchText.isEmpty, homebrew.isInstalled, !homebrew.needsDefinitions {
- if let anotherAccount = homebrew.belongsToAnotherAccount {
- Notice(title: Text("Homebrew Belongs to Another Account"), detail: Text(anotherAccount), kind: .note) {}
- .padding(.vertical, 6)
- .listRowSeparator(.hidden)
+ if let reason = homebrew.whyItCantChange {
+ cantChange(reason)
}
installation
// On macOS 27 what Homebrew said, or didn't, comes right under its section, before maintenance.
@@ -76,7 +74,7 @@ struct HomebrewList: View {
: homebrew.refusedBrew != nil ? "Peel Doesn’t Run This Homebrew"
: !homebrew.isInstalled ? "Homebrew Isn’t Installed"
: !homebrew.needsDefinitions ? nil
- : homebrew.mayChange ? "Homebrew Has to Update First" : "Homebrew Belongs to Another Account",
+ : homebrew.whyItCantChange?.title ?? "Homebrew Has to Update First",
wasStopped: homebrew.scanRun.wasStopped
)
.toolbar {
@@ -448,10 +446,8 @@ struct HomebrewList: View {
@ViewBuilder
private var updateFirst: some View {
- if let anotherAccount = homebrew.belongsToAnotherAccount {
- Notice(title: Text("Homebrew Belongs to Another Account"), detail: Text(anotherAccount), kind: .note) {}
- .padding(.vertical, 6)
- .listRowSeparator(.hidden)
+ if let reason = homebrew.whyItCantChange {
+ cantChange(reason)
} else {
Notice(
title: Text("Homebrew Has to Update First"),
@@ -466,6 +462,16 @@ struct HomebrewList: View {
}
}
+ private func cantChange(_ reason: HomebrewLibrary.CantChange) -> some View {
+ Notice(title: Text(reason.title), detail: Text(reason.detail), kind: .note) {
+ if let command = reason.command {
+ CopyButton(text: command)
+ }
+ }
+ .padding(.vertical, 6)
+ .listRowSeparator(.hidden)
+ }
+
private func count(of kind: HomebrewPackage.Kind) -> Text {
guard let count = homebrew.count(of: kind) else {
return Text(verbatim: String(localized: "Unknown (Homebrew count)", defaultValue: "Unknown"))
@@ -756,12 +762,16 @@ struct HomebrewList: View {
Button("Homebrew Is in Another Folder") { SettingsPane.general.open(with: openSettings) }
}
} else if homebrew.needsDefinitions, homebrew.packages?.isEmpty != false, homebrew.runningCommand == nil,
- let anotherAccount = homebrew.belongsToAnotherAccount {
- ContentUnavailableView(
- "Homebrew Belongs to Another Account",
- systemImage: "person.crop.circle.badge.exclamationmark",
- description: Text(anotherAccount)
- )
+ let reason = homebrew.whyItCantChange {
+ ContentUnavailableView {
+ Label(reason.title, systemImage: "person.crop.circle.badge.exclamationmark")
+ } description: {
+ Text(reason.detail)
+ } actions: {
+ if let command = reason.command {
+ CopyButton(text: command)
+ }
+ }
} else if homebrew.needsDefinitions, homebrew.packages?.isEmpty != false, homebrew.runningCommand == nil {
ContentUnavailableView {
Label("Homebrew Has to Update First", systemImage: "arrow.down.circle")
diff --git a/PeelTests/HomebrewLibraryTests.swift b/PeelTests/HomebrewLibraryTests.swift
index 0cf125b1..735a3478 100644
--- a/PeelTests/HomebrewLibraryTests.swift
+++ b/PeelTests/HomebrewLibraryTests.swift
@@ -81,6 +81,7 @@ private struct StandInBrew {
#expect(homebrew.needsDefinitions)
#expect(homebrew.installation?.version == "7.0.0")
#expect(!homebrew.mayChange)
+ #expect(homebrew.whyItCantChange?.command == "chmod u+w '\(PathPattern.comparablePath(of: brew.folder))'")
}
@Test func oneBrewsFigureDoesNotOutliveTheChoiceOfAnother() async throws {