Skip to content

Commit

Permalink
Merge pull request #3377 from maxim-belkin/extend-pathname
Browse files Browse the repository at this point in the history
pathname: new methods and improvements
  • Loading branch information
MikeMcQuaid committed Nov 10, 2017
2 parents 5318907 + de0b93f commit ee41721
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
19 changes: 19 additions & 0 deletions Library/Homebrew/extend/os/linux/extend/pathname.rb
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
2 changes: 0 additions & 2 deletions Library/Homebrew/extend/os/mac/hardware/cpu.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "os/mac/pathname"

module Hardware
class CPU
class << self
Expand Down
5 changes: 5 additions & 0 deletions Library/Homebrew/extend/os/pathname.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if OS.mac?
require "extend/os/mac/extend/pathname"
elsif OS.linux?
require "extend/os/linux/extend/pathname"
end
7 changes: 6 additions & 1 deletion Library/Homebrew/extend/pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ def atomic_write(content)
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!
Expand Down Expand Up @@ -376,7 +379,7 @@ def ensure_writable
saved_perms = nil
unless writable_real?
saved_perms = stat.mode
chmod 0644
FileUtils.chmod "u+rw", to_path
end
yield
ensure
Expand Down Expand Up @@ -469,6 +472,8 @@ def inspect
end
end

require "extend/os/pathname"

# @private
module ObserverPathnameExtension
class << self
Expand Down
1 change: 0 additions & 1 deletion Library/Homebrew/os/mac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require "os/mac/version"
require "os/mac/xcode"
require "os/mac/xquartz"
require "os/mac/pathname"
require "os/mac/sdk"
require "os/mac/keg"

Expand Down

0 comments on commit ee41721

Please sign in to comment.