From a8cf6daa940e0f76b4e41567945587434a5e3a2b Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Wed, 17 May 2023 12:07:20 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Check=20for=20/usr/local/homebre?= =?UTF-8?q?w=20directory=20(#251)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For this to work, Homebrew cannot be installed in /usr/local, which means that the /usr/local/Cellar folder will be missing and the folder /usr/local/homebrew will exist. --- phpmon/Common/Core/Paths.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/phpmon/Common/Core/Paths.swift b/phpmon/Common/Core/Paths.swift index 18c80e6..fffecb5 100644 --- a/phpmon/Common/Core/Paths.swift +++ b/phpmon/Common/Core/Paths.swift @@ -19,7 +19,17 @@ public class Paths { private var userName: String init() { + // Assume the default directory is correct baseDir = App.architecture != "x86_64" ? .opt : .usr + + // Ensure that if a different location is used, it takes precendence + if baseDir == .usr + && FileSystem.directoryExists("/usr/local/homebrew") + && !FileSystem.directoryExists("/usr/local/Cellar") { + Log.warn("Using /usr/local/homebrew as base directory!") + baseDir = .usr_hb + } + userName = identity() Log.info("The current username is `\(userName)`.") } @@ -100,6 +110,8 @@ public class Paths { Paths.composer = "/usr/local/bin/composer" } else if FileSystem.fileExists("/opt/homebrew/bin/composer") { Paths.composer = "/opt/homebrew/bin/composer" + } else if FileSystem.fileExists("/usr/local/homebrew/bin/composer") { + Paths.composer = "/usr/local/homebrew/bin/composer" } else { Paths.composer = nil Log.warn("Composer was not found.") @@ -111,6 +123,7 @@ public class Paths { public enum HomebrewDir: String { case opt = "/opt/homebrew" case usr = "/usr/local" + case usr_hb = "/usr/local/homebrew" } }