mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Retry to merge fileutils-1.1.0.
* Revert "Revert "Merge fileutils-1.1.0.""
This reverts commit 84bb8e81c2
.
* Added workaround for make mjit-headers
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a95369b33d
commit
60fbe01353
3 changed files with 67 additions and 31 deletions
|
@ -1,14 +1,14 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "fileutils"
|
s.name = "fileutils"
|
||||||
s.version = '1.0.2'
|
s.version = '1.1.0'
|
||||||
s.date = '2017-12-22'
|
|
||||||
s.summary = "Several file utility methods for copying, moving, removing, etc."
|
s.summary = "Several file utility methods for copying, moving, removing, etc."
|
||||||
s.description = "Several file utility methods for copying, moving, removing, etc."
|
s.description = "Several file utility methods for copying, moving, removing, etc."
|
||||||
|
|
||||||
s.require_path = %w{lib}
|
s.require_path = %w{lib}
|
||||||
s.files = [".gitignore", ".travis.yml", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "bin/console", "bin/setup", "fileutils.gemspec", "lib/fileutils.rb"]
|
s.files = [".gitignore", ".travis.yml", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "bin/console", "bin/setup", "fileutils.gemspec", "lib/fileutils.rb"]
|
||||||
s.required_ruby_version = ">= 2.4.0"
|
s.required_ruby_version = ">= 2.3.0"
|
||||||
|
|
||||||
s.authors = ["Minero Aoki"]
|
s.authors = ["Minero Aoki"]
|
||||||
s.email = [nil]
|
s.email = [nil]
|
||||||
|
|
|
@ -85,9 +85,15 @@
|
||||||
# <tt>:verbose</tt> flags to methods in FileUtils.
|
# <tt>:verbose</tt> flags to methods in FileUtils.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
begin
|
||||||
|
require 'rbconfig'
|
||||||
|
rescue LoadError
|
||||||
|
# for make mjit-headers
|
||||||
|
end
|
||||||
|
|
||||||
module FileUtils
|
module FileUtils
|
||||||
|
|
||||||
VERSION = "1.0.2"
|
VERSION = "1.1.0"
|
||||||
|
|
||||||
def self.private_module_function(name) #:nodoc:
|
def self.private_module_function(name) #:nodoc:
|
||||||
module_function name
|
module_function name
|
||||||
|
@ -119,8 +125,9 @@ module FileUtils
|
||||||
#
|
#
|
||||||
def cd(dir, verbose: nil, &block) # :yield: dir
|
def cd(dir, verbose: nil, &block) # :yield: dir
|
||||||
fu_output_message "cd #{dir}" if verbose
|
fu_output_message "cd #{dir}" if verbose
|
||||||
Dir.chdir(dir, &block)
|
result = Dir.chdir(dir, &block)
|
||||||
fu_output_message 'cd -' if verbose and block
|
fu_output_message 'cd -' if verbose and block
|
||||||
|
result
|
||||||
end
|
end
|
||||||
module_function :cd
|
module_function :cd
|
||||||
|
|
||||||
|
@ -541,7 +548,7 @@ module FileUtils
|
||||||
module_function :move
|
module_function :move
|
||||||
|
|
||||||
def rename_cannot_overwrite_file? #:nodoc:
|
def rename_cannot_overwrite_file? #:nodoc:
|
||||||
/emx/ =~ RUBY_PLATFORM
|
/emx/ =~ RbConfig::CONFIG['host_os']
|
||||||
end
|
end
|
||||||
private_module_function :rename_cannot_overwrite_file?
|
private_module_function :rename_cannot_overwrite_file?
|
||||||
|
|
||||||
|
@ -681,22 +688,38 @@ module FileUtils
|
||||||
unless parent_st.sticky?
|
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})"
|
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
|
end
|
||||||
|
|
||||||
# freeze tree root
|
# freeze tree root
|
||||||
euid = Process.euid
|
euid = Process.euid
|
||||||
File.open(fullpath + '/.') {|f|
|
dot_file = fullpath + "/."
|
||||||
unless fu_stat_identical_entry?(st, f.stat)
|
begin
|
||||||
# symlink (TOC-to-TOU attack?)
|
File.open(dot_file) {|f|
|
||||||
File.unlink fullpath
|
unless fu_stat_identical_entry?(st, f.stat)
|
||||||
return
|
# symlink (TOC-to-TOU attack?)
|
||||||
end
|
File.unlink fullpath
|
||||||
f.chown euid, -1
|
return
|
||||||
f.chmod 0700
|
end
|
||||||
unless fu_stat_identical_entry?(st, File.lstat(fullpath))
|
f.chown euid, -1
|
||||||
# TOC-to-TOU attack?
|
f.chmod 0700
|
||||||
File.unlink fullpath
|
}
|
||||||
return
|
rescue EISDIR # JRuby in non-native mode can't open files as dirs
|
||||||
end
|
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 ----
|
# ---- tree root is frozen ----
|
||||||
root = Entry_.new(path)
|
root = Entry_.new(path)
|
||||||
root.preorder_traverse do |ent|
|
root.preorder_traverse do |ent|
|
||||||
|
@ -797,8 +820,15 @@ module FileUtils
|
||||||
#
|
#
|
||||||
def compare_stream(a, b)
|
def compare_stream(a, b)
|
||||||
bsize = fu_stream_blksize(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
|
begin
|
||||||
a.read(bsize, sa)
|
a.read(bsize, sa)
|
||||||
b.read(bsize, sb)
|
b.read(bsize, sb)
|
||||||
|
@ -1123,7 +1153,7 @@ module FileUtils
|
||||||
private
|
private
|
||||||
|
|
||||||
def fu_windows?
|
def fu_windows?
|
||||||
/mswin|mingw|bccwin|emx/ =~ RUBY_PLATFORM
|
/mswin|mingw|bccwin|emx/ =~ RbConfig::CONFIG['host_os']
|
||||||
end
|
end
|
||||||
|
|
||||||
def fu_copy_stream0(src, dest, blksize = nil) #:nodoc:
|
def fu_copy_stream0(src, dest, blksize = nil) #:nodoc:
|
||||||
|
|
|
@ -233,7 +233,7 @@ class TestFileUtils < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_assert_output_lines
|
def test_assert_output_lines
|
||||||
assert_raise(MiniTest::Assertion) {
|
assert_raise(MiniTest::Assertion) {
|
||||||
Timeout.timeout(0.1) {
|
Timeout.timeout(0.5) {
|
||||||
assert_output_lines([]) {
|
assert_output_lines([]) {
|
||||||
Thread.current.report_on_exception = false
|
Thread.current.report_on_exception = false
|
||||||
raise "ok"
|
raise "ok"
|
||||||
|
@ -834,13 +834,15 @@ class TestFileUtils < Test::Unit::TestCase
|
||||||
check_singleton :ln_s
|
check_singleton :ln_s
|
||||||
|
|
||||||
TARGETS.each do |fname|
|
TARGETS.each do |fname|
|
||||||
fname = "../#{fname}"
|
begin
|
||||||
lnfname = 'tmp/lnsdest'
|
fname = "../#{fname}"
|
||||||
ln_s fname, lnfname
|
lnfname = 'tmp/lnsdest'
|
||||||
assert FileTest.symlink?(lnfname), 'not symlink'
|
ln_s fname, lnfname
|
||||||
assert_equal fname, File.readlink(lnfname)
|
assert FileTest.symlink?(lnfname), 'not symlink'
|
||||||
ensure
|
assert_equal fname, File.readlink(lnfname)
|
||||||
rm_f lnfname
|
ensure
|
||||||
|
rm_f lnfname
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end if have_symlink? and !no_broken_symlink?
|
end if have_symlink? and !no_broken_symlink?
|
||||||
|
|
||||||
|
@ -1613,6 +1615,10 @@ class TestFileUtils < Test::Unit::TestCase
|
||||||
check_singleton :cd
|
check_singleton :cd
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_cd_result
|
||||||
|
assert_equal 42, cd('.') { 42 }
|
||||||
|
end
|
||||||
|
|
||||||
def test_chdir
|
def test_chdir
|
||||||
check_singleton :chdir
|
check_singleton :chdir
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue