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

ruby-changes:34700

From: hsbt <ko1@a...>
Date: Fri, 11 Jul 2014 16:51:35 +0900 (JST)
Subject: [ruby-changes:34700] hsbt:r46783 (trunk): * lib/fileutils.rb: handle ENOENT error with symlink targeted to

hsbt	2014-07-11 16:51:19 +0900 (Fri, 11 Jul 2014)

  New Revision: 46783

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

  Log:
    * lib/fileutils.rb: handle ENOENT error with symlink targeted to
      non-exists file. [ruby-dev:45933] [Bug #6716]

  Modified files:
    trunk/ChangeLog
    trunk/lib/fileutils.rb
    trunk/test/fileutils/test_fileutils.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46782)
+++ ChangeLog	(revision 46783)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jul 11 16:45:39 2014  SHIBATA Hiroshi  <shibata.hiroshi@g...>
+
+	* lib/fileutils.rb: handle ENOENT error with symlink targeted to
+	  non-exists file. [ruby-dev:45933] [Bug #6716]
+
 Fri Jul 11 15:59:42 2014  SHIBATA Hiroshi  <shibata.hiroshi@g...>
 
 	* array.c: Clarify documentation for Array#insert.
Index: lib/fileutils.rb
===================================================================
--- lib/fileutils.rb	(revision 46782)
+++ lib/fileutils.rb	(revision 46783)
@@ -856,7 +856,8 @@ module FileUtils https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L856
     fu_check_options options, OPT_TABLE['install']
     fu_output_message "install -c#{options[:preserve] && ' -p'}#{options[:mode] ? (' -m 0%o' % options[:mode]) : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
     return if options[:noop]
-    fu_each_src_dest(src, dest) do |s, d, st|
+    fu_each_src_dest(src, dest) do |s, d|
+      st = File.stat(s)
       unless File.exist?(d) and compare_file(s, d)
         remove_file d, true
         copy_file s, d
@@ -1242,7 +1243,12 @@ module FileUtils https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1243
     end
 
     def exist?
-      lstat! ? true : false
+      begin
+        lstat
+        true
+      rescue Errno::ENOENT
+        false
+      end
     end
 
     def file?
@@ -1560,7 +1566,7 @@ module FileUtils https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1566
   def fu_each_src_dest(src, dest)   #:nodoc:
     fu_each_src_dest0(src, dest) do |s, d|
       raise ArgumentError, "same file: #{s} and #{d}" if fu_same?(s, d)
-      yield s, d, File.stat(s)
+      yield s, d
     end
   end
   private_module_function :fu_each_src_dest
Index: test/fileutils/test_fileutils.rb
===================================================================
--- test/fileutils/test_fileutils.rb	(revision 46782)
+++ test/fileutils/test_fileutils.rb	(revision 46783)
@@ -445,6 +445,12 @@ class TestFileUtils < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L445
     assert_raise(Errno::ELOOP) {
       mv 'tmp/symlink', 'tmp/symlink'
     }
+    # unexist symlink
+    File.symlink 'xxx', 'tmp/src'
+    assert_nothing_raised {
+      mv 'tmp/src', 'tmp/dest'
+    }
+    assert_equal true, File.symlink?('tmp/dest')
   end if have_symlink?
 
   def test_mv_pathname

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

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