Merge pull request #3377 from maxim-belkin/extend-pathname

pathname: new methods and improvements
This commit is contained in:
Mike McQuaid 2017-11-10 17:49:27 +00:00 committed by GitHub
commit ee4172159b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 4 deletions

View File

@ -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

View File

@ -1,5 +1,3 @@
require "os/mac/pathname"
module Hardware
class CPU
class << self

View File

@ -0,0 +1,5 @@
if OS.mac?
require "extend/os/mac/extend/pathname"
elsif OS.linux?
require "extend/os/linux/extend/pathname"
end

View File

@ -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

View File

@ -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"