From e66ebe8b3f1b8ab19278a0bf0cfab75e9c01e80f Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Sun, 29 Sep 2024 13:40:10 +0800 Subject: [PATCH] os/linux/ld: handle nonexistent `ld.so.conf` more gracefully Fixes #18458 --- Library/Homebrew/os/linux/ld.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/os/linux/ld.rb b/Library/Homebrew/os/linux/ld.rb index 9227792b29920..f1baa172a59e9 100644 --- a/Library/Homebrew/os/linux/ld.rb +++ b/Library/Homebrew/os/linux/ld.rb @@ -23,14 +23,19 @@ def self.brewed_ld_so_diagnostics sig { returns(String) } def self.sysconfdir - fallback_sysconfdir = "/etc" - match = brewed_ld_so_diagnostics.match(/path.sysconfdir="(.+)"/) return fallback_sysconfdir unless match match.captures.compact.first || fallback_sysconfdir end + sig { returns(String) } + def self.fallback_sysconfdir + return "/usr/share/defaults/etc" if File.exist?("/usr/share/defaults/etc/ld.so.conf") + + "/etc" + end + sig { returns(T::Array[String]) } def self.system_dirs dirs = [] @@ -45,9 +50,21 @@ def self.system_dirs dirs end + FALLBACK_LIBRARY_PATHS = %w[ + /usr/local/lib + /usr/local/lib/x86_64-linux-gnu + /lib/x86_64-linux-gnu + /usr/lib/x86_64-linux-gnu + ].freeze + sig { params(conf_path: T.any(Pathname, String)).returns(T::Array[String]) } def self.library_paths(conf_path = Pathname(sysconfdir)/"ld.so.conf") conf_file = Pathname(conf_path) + unless conf_file.exist? + opoo "Could not find your `ld.so.conf`; Falling back to built-in defaults." + return FALLBACK_LIBRARY_PATHS + end + paths = Set.new directory = conf_file.realpath.dirname