diff options
| author | Maxim Belkin | 2017-11-07 14:18:25 -0600 |
|---|---|---|
| committer | Maxim Belkin | 2017-11-07 14:18:25 -0600 |
| commit | de0b93f912f014155423ed9a679dcd99c40f2622 (patch) | |
| tree | 76f2813a755798b3b7159abb0d9e5c97dac8cd07 /Library | |
| parent | 0cec599b28c23fb6bade4202fd455d54c07dfd27 (diff) | |
| download | brew-de0b93f912f014155423ed9a679dcd99c40f2622.tar.bz2 | |
pathname: improvements, cleanups, and new methods
- atomic_write: close file before renaming to prevent error:
'Device or resource busy'
- ensure_writable: preserve executable bit
- new elf? and dynamic? methods
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/extend/os/linux/extend/pathname.rb | 19 | ||||
| -rw-r--r-- | Library/Homebrew/extend/os/mac/extend/pathname.rb (renamed from Library/Homebrew/os/mac/pathname.rb) | 0 | ||||
| -rw-r--r-- | Library/Homebrew/extend/os/mac/hardware/cpu.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/extend/os/pathname.rb | 5 | ||||
| -rw-r--r-- | Library/Homebrew/extend/pathname.rb | 7 | ||||
| -rw-r--r-- | Library/Homebrew/os/mac.rb | 1 |
6 files changed, 30 insertions, 4 deletions
diff --git a/Library/Homebrew/extend/os/linux/extend/pathname.rb b/Library/Homebrew/extend/os/linux/extend/pathname.rb new file mode 100644 index 000000000..eb6ea409b --- /dev/null +++ b/Library/Homebrew/extend/os/linux/extend/pathname.rb @@ -0,0 +1,19 @@ +class Pathname + # @private + def elf? + # See: https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header + read(4) == "\x7fELF" + end + + # @private + def dynamic_elf? + if which "readelf" + popen_read("readelf", "-l", to_path).include?(" DYNAMIC ") + elsif which "file" + !popen_read("file", "-L", "-b", to_path)[/dynamic|shared/].nil? + else + raise StandardError, "Neither `readelf` nor `file` is available "\ + "to determine whether '#{self}' is dynamically or statically linked." + end + end +end diff --git a/Library/Homebrew/os/mac/pathname.rb b/Library/Homebrew/extend/os/mac/extend/pathname.rb index 5fd59e1e7..5fd59e1e7 100644 --- a/Library/Homebrew/os/mac/pathname.rb +++ b/Library/Homebrew/extend/os/mac/extend/pathname.rb diff --git a/Library/Homebrew/extend/os/mac/hardware/cpu.rb b/Library/Homebrew/extend/os/mac/hardware/cpu.rb index b97c280cd..a216db6ae 100644 --- a/Library/Homebrew/extend/os/mac/hardware/cpu.rb +++ b/Library/Homebrew/extend/os/mac/hardware/cpu.rb @@ -1,5 +1,3 @@ -require "os/mac/pathname" - module Hardware class CPU class << self diff --git a/Library/Homebrew/extend/os/pathname.rb b/Library/Homebrew/extend/os/pathname.rb new file mode 100644 index 000000000..5e6edeb30 --- /dev/null +++ b/Library/Homebrew/extend/os/pathname.rb @@ -0,0 +1,5 @@ +if OS.mac? + require "extend/os/mac/extend/pathname" +elsif OS.linux? + require "extend/os/linux/extend/pathname" +end diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index b4c7ca959..82cf10be0 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -189,6 +189,9 @@ class Pathname rescue Errno::EPERM # rubocop:disable Lint/HandleExceptions end + # Close the file before renaming to prevent the error: Device or resource busy + # Affects primarily NFS. + tf.close File.rename(tf.path, self) ensure tf.close! @@ -376,7 +379,7 @@ class Pathname saved_perms = nil unless writable_real? saved_perms = stat.mode - chmod 0644 + FileUtils.chmod "u+rw", to_path end yield ensure @@ -469,6 +472,8 @@ class Pathname end end +require "extend/os/pathname" + # @private module ObserverPathnameExtension class << self diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index cb4141f48..a5e12c924 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -3,7 +3,6 @@ require "development_tools" require "os/mac/version" require "os/mac/xcode" require "os/mac/xquartz" -require "os/mac/pathname" require "os/mac/sdk" require "os/mac/keg" |
