Skip to content

Commit

Permalink
os/linux/ld: handle nonexistent ld.so.conf more gracefully
Browse files Browse the repository at this point in the history
Fixes #18458
  • Loading branch information
carlocab committed Sep 30, 2024
1 parent d767c96 commit e66ebe8
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Library/Homebrew/os/linux/ld.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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

Check warning on line 65 in Library/Homebrew/os/linux/ld.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/os/linux/ld.rb#L65

Added line #L65 was not covered by tests
end

paths = Set.new
directory = conf_file.realpath.dirname

Expand Down

0 comments on commit e66ebe8

Please sign in to comment.