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

ruby-changes:15918

From: usa <ko1@a...>
Date: Mon, 17 May 2010 11:10:57 +0900 (JST)
Subject: [ruby-changes:15918] Ruby:r27858 (ruby_1_9_2): merge from trunk (r27856, r27857)

usa	2010-05-17 11:10:42 +0900 (Mon, 17 May 2010)

  New Revision: 27858

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

  Log:
    merge from trunk (r27856, r27857)
    
    * lib/fileutils.rb (FileUtils::Entry_#entries): returns pathname in
      UTF-8 on Windows to allow FileUtils accessing all pathnames
      internally.

  Modified files:
    branches/ruby_1_9_2/ChangeLog
    branches/ruby_1_9_2/lib/fileutils.rb
    branches/ruby_1_9_2/test/ruby/test_dir_m17n.rb

Index: ruby_1_9_2/ChangeLog
===================================================================
--- ruby_1_9_2/ChangeLog	(revision 27857)
+++ ruby_1_9_2/ChangeLog	(revision 27858)
@@ -1,3 +1,9 @@
+Mon May 17 11:09:58 2010  NAKAMURA Usaku  <usa@r...>
+
+	* lib/fileutils.rb (FileUtils::Entry_#entries): returns pathname in
+	  UTF-8 on Windows to allow FileUtils accessing all pathnames
+	  internally.
+
  Sun May 16 22:21:32 2010  Yusuke Endoh  <mame@t...>
  
  	* proc.c (mnew): initialize a field.  a patch from Takahiro Kambe.
Index: ruby_1_9_2/lib/fileutils.rb
===================================================================
--- ruby_1_9_2/lib/fileutils.rb	(revision 27857)
+++ ruby_1_9_2/lib/fileutils.rb	(revision 27858)
@@ -1176,7 +1176,9 @@
     end
 
     def entries
-      Dir.entries(path())\
+      opts = {}
+      opts[:encoding] = "UTF-8" if /mswin|mignw/ =~ RUBY_PLATFORM
+      Dir.entries(path(), opts)\
           .reject {|n| n == '.' or n == '..' }\
           .map {|n| Entry_.new(prefix(), join(rel(), n.untaint)) }
     end
Index: ruby_1_9_2/test/ruby/test_dir_m17n.rb
===================================================================
--- ruby_1_9_2/test/ruby/test_dir_m17n.rb	(revision 27857)
+++ ruby_1_9_2/test/ruby/test_dir_m17n.rb	(revision 27858)
@@ -18,25 +18,29 @@
       assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d)
         filename = "\u3042"
         File.open(filename, "w") {}
-        ents = Dir.entries(".")
+        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
+        ents = Dir.entries(".", opts)
         exit ents.include?(filename)
       EOS
     }
   end
 
   def test_filename_extutf8_invalid
+    skip "ruby on windows doesn't support invalid utf-8 path" if /mswin|mingw/ =~ RUBY_PLATFORM
     with_tmpdir {|d|
       assert_ruby_status(%w[-EASCII-8BIT], <<-'EOS', nil, :chdir=>d)
         filename = "\xff".force_encoding("ASCII-8BIT") # invalid byte sequence as UTF-8
         File.open(filename, "w") {}
-        ents = Dir.entries(".")
-        exit ents.include?(filename) || (RUBY_PLATFORM =~ /darwin/ && ents.include?("%FF"))
+        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
+        ents = Dir.entries(".", opts)
+        exit ents.include?(filename) || ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%FF"))
       EOS
       assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d)
         filename = "\xff".force_encoding("UTF-8") # invalid byte sequence as UTF-8
         File.open(filename, "w") {}
-        ents = Dir.entries(".")
-        exit ents.include?(filename) || (RUBY_PLATFORM =~ /darwin/ && ents.include?("%FF"))
+        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
+        ents = Dir.entries(".", opts)
+        exit ents.include?(filename) || ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%FF"))
       EOS
     }
   end
@@ -46,11 +50,16 @@
       assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d)
         filename = "\xc2\xa1".force_encoding("utf-8")
         File.open(filename, "w") {}
-        ents = Dir.entries(".")
+        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
+        ents = Dir.entries(".", opts)
         exit ents.include?(filename)
       EOS
       assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d)
-        filename = "\xc2\xa1".force_encoding("euc-jp")
+        if /mswin|mingw/ =~ RUBY_PLATFORM
+          filename = "\x8f\xa2\xc2".force_encoding("euc-jp")
+        else
+          filename = "\xc2\xa1".force_encoding("euc-jp")
+        end
         begin
           open(filename) {}
           exit true
@@ -58,6 +67,7 @@
           exit false
         end
       EOS
+      skip "no meaning test on windows" if /mswin|mingw/ =~ RUBY_PLATFORM
       assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d)
         filename1 = "\xc2\xa1".force_encoding("utf-8")
         filename2 = "\xc2\xa1".force_encoding("euc-jp")
@@ -79,12 +89,14 @@
       assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d)
         filename = "\u3042"
         File.open(filename, "w") {}
-        ents = Dir.entries(".")
+        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
+        ents = Dir.entries(".", opts)
         exit ents.include?(filename)
       EOS
       assert_ruby_status(%w[-EUTF-8:EUC-JP], <<-'EOS', nil, :chdir=>d)
         filename = "\xA4\xA2".force_encoding("euc-jp")
-        ents = Dir.entries(".")
+        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
+        ents = Dir.entries(".", opts)
         exit ents.include?(filename)
       EOS
       assert_ruby_status(%w[-EUTF-8:EUC-JP], <<-'EOS', nil, :chdir=>d)
@@ -106,13 +118,15 @@
         filename2 = "\u3042" # HIRAGANA LETTER A which is representable in EUC-JP
         File.open(filename1, "w") {}
         File.open(filename2, "w") {}
-        ents = Dir.entries(".")
+        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
+        ents = Dir.entries(".", opts)
         exit ents.include?(filename1) && ents.include?(filename2)
       EOS
       assert_ruby_status(%w[-EUTF-8:EUC-JP], <<-'EOS', nil, :chdir=>d)
         filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP
         filename2 = "\xA4\xA2".force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP
-        ents = Dir.entries(".")
+        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
+        ents = Dir.entries(".", opts)
         exit ents.include?(filename1) && ents.include?(filename2)
       EOS
       assert_ruby_status(%w[-EUTF-8:EUC-JP], <<-'EOS', nil, :chdir=>d)
@@ -134,10 +148,11 @@
       assert_ruby_status(%w[-EEUC-JP], <<-'EOS', nil, :chdir=>d)
         filename = "\xA4\xA2".force_encoding("euc-jp")
         File.open(filename, "w") {}
-        ents = Dir.entries(".")
+        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
+        ents = Dir.entries(".", opts)
         ents.each {|e| e.force_encoding("ASCII-8BIT") }
         exit ents.include?(filename.force_encoding("ASCII-8BIT")) ||
-               (RUBY_PLATFORM =~ /darwin/ && ents.include?("%A4%A2".force_encoding("ASCII-8BIT")))
+               ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%A4%A2".force_encoding("ASCII-8BIT")))
       EOS
     }
   end
@@ -147,15 +162,17 @@
       assert_ruby_status(%w[-EEUC-JP], <<-'EOS', nil, :chdir=>d)
         filename = "\xA4\xA2".force_encoding("euc-jp")
         File.open(filename, "w") {}
-        ents = Dir.entries(".")
-        exit ents.include?(filename) ||
-               (RUBY_PLATFORM =~ /darwin/ && ents.include?("%A4%A2".force_encoding("euc-jp")))
+        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
+        ents = Dir.entries(".", opts)
+        exit ents.include?(filename) || ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%A4%A2".force_encoding("euc-jp")))
       EOS
       assert_ruby_status(%w[-EASCII-8BIT], <<-'EOS', nil, :chdir=>d)
         filename = "\xA4\xA2"
-        ents = Dir.entries(".")
+        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
+        ents = Dir.entries(".", opts)
         exit ents.include?(filename) ||
-               (RUBY_PLATFORM =~ /darwin/ && ents.include?("%A4%A2".force_encoding("ASCII-8BIT")))
+               ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%A4%A2".force_encoding("ASCII-8BIT"))) ||
+               ((RUBY_PLATFORM =~ /mswin|mingw/) != nil && ents.include?("\x82\xA0".force_encoding("ASCII-8BIT")))
       EOS
     }
   end
@@ -165,13 +182,15 @@
       assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d)
         filename = "\u3042".force_encoding("utf-8")
         File.open(filename, "w") {}
-        ents = Dir.entries(".")
+        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
+        ents = Dir.entries(".", opts)
         exit ents.include?(filename)
       EOS
       assert_ruby_status(%w[-EASCII-8BIT], <<-'EOS', nil, :chdir=>d)
         filename = "\u3042".force_encoding("ASCII-8BIT")
-        ents = Dir.entries(".")
-        exit ents.include?(filename)
+        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
+        ents = Dir.entries(".", opts)
+        exit ents.include?(filename) || ((RUBY_PLATFORM =~ /mswin|mingw/) != nil && ents.include?("\x82\xA0".force_encoding("ASCII-8BIT")))
       EOS
     }
   end
@@ -181,14 +200,15 @@
       assert_ruby_status(%w[-EEUC-JP], <<-'EOS', nil, :chdir=>d)
         filename = "\xA4\xA2".force_encoding("euc-jp")
         File.open(filename, "w") {}
-        ents = Dir.entries(".")
-        exit ents.include?(filename) ||
-               (RUBY_PLATFORM =~ /darwin/ && ents.include?("%A4%A2".force_encoding("euc-jp")))
+        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
+        ents = Dir.entries(".", opts)
+        exit ents.include?(filename) || ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%A4%A2".force_encoding("euc-jp")))
       EOS
       assert_ruby_status(%w[-EEUC-JP:UTF-8], <<-'EOS', nil, :chdir=>d)
         filename = "\u3042"
-        ents = Dir.entries(".")
-        exit ents.include?(filename) || (RUBY_PLATFORM =~ /darwin/ && ents.include?("%A4%A2"))
+        opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
+        ents = Dir.entries(".", opts)
+        exit ents.include?(filename) || ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%A4%A2"))
       EOS
     }
   end

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

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