[前][次][番号順一覧][スレッド一覧]

ruby-changes:51218

From: hsbt <ko1@a...>
Date: Tue, 15 May 2018 10:22:41 +0900 (JST)
Subject: [ruby-changes:51218] hsbt:r63425 (trunk): Merge fileutils-1.1.0.

hsbt	2018-05-15 10:22:36 +0900 (Tue, 15 May 2018)

  New Revision: 63425

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63425

  Log:
    Merge fileutils-1.1.0.
    
      This version was migrated JRuby paches.
      https://github.com/ruby/fileutils/pull/18

  Modified files:
    trunk/lib/fileutils.gemspec
    trunk/lib/fileutils.rb
    trunk/test/fileutils/test_fileutils.rb
Index: lib/fileutils.gemspec
===================================================================
--- lib/fileutils.gemspec	(revision 63424)
+++ lib/fileutils.gemspec	(revision 63425)
@@ -1,14 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/lib/fileutils.gemspec#L1
 # frozen_string_literal: true
+
 Gem::Specification.new do |s|
   s.name = "fileutils"
-  s.version = '1.0.2'
-  s.date = '2017-12-22'
+  s.version = '1.1.0'
   s.summary = "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.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.email = [nil]
Index: lib/fileutils.rb
===================================================================
--- lib/fileutils.rb	(revision 63424)
+++ lib/fileutils.rb	(revision 63425)
@@ -85,9 +85,11 @@ https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L85
 # <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 https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L121
   #
   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 https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L544
   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 https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L684
     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 https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L816
   #
   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 https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1149
     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:
Index: test/fileutils/test_fileutils.rb
===================================================================
--- test/fileutils/test_fileutils.rb	(revision 63424)
+++ test/fileutils/test_fileutils.rb	(revision 63425)
@@ -233,7 +233,7 @@ class TestFileUtils < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L233
 
   def test_assert_output_lines
     assert_raise(MiniTest::Assertion) {
-      Timeout.timeout(0.1) {
+      Timeout.timeout(0.5) {
         assert_output_lines([]) {
           Thread.current.report_on_exception = false
           raise "ok"
@@ -834,13 +834,15 @@ class TestFileUtils < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L834
     check_singleton :ln_s
 
     TARGETS.each do |fname|
-      fname = "../#{fname}"
-      lnfname = 'tmp/lnsdest'
-      ln_s fname, lnfname
-      assert FileTest.symlink?(lnfname), 'not symlink'
-      assert_equal fname, File.readlink(lnfname)
-    ensure
-      rm_f lnfname
+      begin
+        fname = "../#{fname}"
+        lnfname = 'tmp/lnsdest'
+        ln_s fname, lnfname
+        assert FileTest.symlink?(lnfname), 'not symlink'
+        assert_equal fname, File.readlink(lnfname)
+      ensure
+        rm_f lnfname
+      end
     end
   end if have_symlink? and !no_broken_symlink?
 
@@ -1613,6 +1615,10 @@ class TestFileUtils < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L1615
     check_singleton :cd
   end
 
+  def test_cd_result
+    assert_equal 42, cd('.') { 42 }
+  end
+
   def test_chdir
     check_singleton :chdir
   end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]