summaryrefslogtreecommitdiff
path: root/lib/fileutils.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-15 01:22:36 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-15 01:22:36 +0000
commit6f9609867cdd4bf965465d0aabe0e8e6c665e9c0 (patch)
treee2ccfc78ad8d67aa8284ae8426d9f6afc12683b7 /lib/fileutils.rb
parentee1b07b675ec034f8a91065598c4848a0a99eee0 (diff)
downloadruby-6f9609867cdd4bf965465d0aabe0e8e6c665e9c0.tar.gz
Merge fileutils-1.1.0.
This version was migrated JRuby paches. https://github.com/ruby/fileutils/pull/18 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/fileutils.rb')
-rw-r--r--lib/fileutils.rb66
1 files changed, 46 insertions, 20 deletions
diff --git a/lib/fileutils.rb b/lib/fileutils.rb
index 88e28f29d5..7cbc6f46fa 100644
--- a/lib/fileutils.rb
+++ b/lib/fileutils.rb
@@ -85,9 +85,11 @@
# <tt>:verbose</tt> flags to methods in FileUtils.
#
+require 'rbconfig'
+
module FileUtils
- VERSION = "1.0.2"
+ VERSION = "1.1.0"
def self.private_module_function(name) #:nodoc:
module_function name
@@ -119,8 +121,9 @@ module FileUtils
#
def cd(dir, verbose: nil, &block) # :yield: dir
fu_output_message "cd #{dir}" if verbose
- Dir.chdir(dir, &block)
+ result = Dir.chdir(dir, &block)
fu_output_message 'cd -' if verbose and block
+ result
end
module_function :cd
@@ -541,7 +544,7 @@ module FileUtils
module_function :move
def rename_cannot_overwrite_file? #:nodoc:
- /emx/ =~ RUBY_PLATFORM
+ /emx/ =~ RbConfig::CONFIG['host_os']
end
private_module_function :rename_cannot_overwrite_file?
@@ -681,22 +684,38 @@ module FileUtils
unless parent_st.sticky?
raise ArgumentError, "parent directory is world writable, FileUtils#remove_entry_secure does not work; abort: #{path.inspect} (parent directory mode #{'%o' % parent_st.mode})"
end
+
# freeze tree root
euid = Process.euid
- File.open(fullpath + '/.') {|f|
- unless fu_stat_identical_entry?(st, f.stat)
- # symlink (TOC-to-TOU attack?)
- File.unlink fullpath
- return
- end
- f.chown euid, -1
- f.chmod 0700
- unless fu_stat_identical_entry?(st, File.lstat(fullpath))
- # TOC-to-TOU attack?
- File.unlink fullpath
- return
- end
- }
+ dot_file = fullpath + "/."
+ begin
+ File.open(dot_file) {|f|
+ unless fu_stat_identical_entry?(st, f.stat)
+ # symlink (TOC-to-TOU attack?)
+ File.unlink fullpath
+ return
+ end
+ f.chown euid, -1
+ f.chmod 0700
+ }
+ rescue EISDIR # JRuby in non-native mode can't open files as dirs
+ File.lstat(dot_file).tap {|fstat|
+ unless fu_stat_identical_entry?(st, fstat)
+ # symlink (TOC-to-TOU attack?)
+ File.unlink fullpath
+ return
+ end
+ File.chown euid, -1, dot_file
+ File.chmod 0700, dot_file
+ }
+ end
+
+ unless fu_stat_identical_entry?(st, File.lstat(fullpath))
+ # TOC-to-TOU attack?
+ File.unlink fullpath
+ return
+ end
+
# ---- tree root is frozen ----
root = Entry_.new(path)
root.preorder_traverse do |ent|
@@ -797,8 +816,15 @@ module FileUtils
#
def compare_stream(a, b)
bsize = fu_stream_blksize(a, b)
- sa = String.new(capacity: bsize)
- sb = String.new(capacity: bsize)
+
+ if RUBY_VERSION > "2.4"
+ sa = String.new(capacity: bsize)
+ sb = String.new(capacity: bsize)
+ else
+ sa = String.new
+ sb = String.new
+ end
+
begin
a.read(bsize, sa)
b.read(bsize, sb)
@@ -1123,7 +1149,7 @@ module FileUtils
private
def fu_windows?
- /mswin|mingw|bccwin|emx/ =~ RUBY_PLATFORM
+ /mswin|mingw|bccwin|emx/ =~ RbConfig::CONFIG['host_os']
end
def fu_copy_stream0(src, dest, blksize = nil) #:nodoc: