aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/extend/os/linux
diff options
context:
space:
mode:
authorMaxim Belkin2017-11-07 14:18:25 -0600
committerMaxim Belkin2017-11-07 14:18:25 -0600
commitde0b93f912f014155423ed9a679dcd99c40f2622 (patch)
tree76f2813a755798b3b7159abb0d9e5c97dac8cd07 /Library/Homebrew/extend/os/linux
parent0cec599b28c23fb6bade4202fd455d54c07dfd27 (diff)
downloadbrew-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/Homebrew/extend/os/linux')
-rw-r--r--Library/Homebrew/extend/os/linux/extend/pathname.rb19
1 files changed, 19 insertions, 0 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