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

ruby-changes:61678

From: Kazuhiro <ko1@a...>
Date: Thu, 11 Jun 2020 16:53:19 +0900 (JST)
Subject: [ruby-changes:61678] 59646e8e29 (master): Fix error in `remove_entry`

https://git.ruby-lang.org/ruby.git/commit/?id=59646e8e29

From 59646e8e29e58bd6b4d0e622e76072ee47d0ae34 Mon Sep 17 00:00:00 2001
From: Kazuhiro NISHIYAMA <zn@m...>
Date: Thu, 11 Jun 2020 16:29:31 +0900
Subject: Fix error in `remove_entry`

When `LANG=C`, dir is `UTF-8` and `base` is 'ASCII-8BIT` in `FileUtils::Entry_#join`.
So `Encoding::CompatibilityError` occurred and files are not removed.

https://rubyci.org/logs/rubyci.s3.amazonaws.com/arch/ruby-master/log/20200611T060002Z.fail.html.gz
```
  1) Error:
WEBrick::TestFileHandler#test_cjk_in_path:
Errno::ENOTEMPTY: Directory not empty @ dir_s_rmdir - /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/tmp/???20200611-1887828-3nn72a
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:1460:in `rmdir'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:1460:in `block in remove_dir1'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:1471:in `platform_support'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:1459:in `remove_dir1'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:1452:in `remove'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:780:in `block in remove_entry'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:1509:in `ensure in postorder_traverse'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:1509:in `postorder_traverse'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:778:in `remove_entry'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/tmpdir.rb:97:in `mktmpdir'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/test/webrick/test_filehandler.rb:292:in `test_cjk_in_path'
```

diff --git a/lib/fileutils.rb b/lib/fileutils.rb
index 04788e2..baa3d18 100644
--- a/lib/fileutils.rb
+++ b/lib/fileutils.rb
@@ -1290,7 +1290,7 @@ module FileUtils https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1290
 
     def entries
       opts = {}
-      opts[:encoding] = ::Encoding::UTF_8 if fu_windows?
+      opts[:encoding] = path.encoding
 
       files = if Dir.respond_to?(:children)
         Dir.children(path, **opts)
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb
index ca435ed1..4951ca4 100644
--- a/test/fileutils/test_fileutils.rb
+++ b/test/fileutils/test_fileutils.rb
@@ -741,6 +741,17 @@ class TestFileUtils < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L741
     assert_file_not_exist 'tmp/tmpdir3'
   end
 
+  def test_remove_entry_cjk_path
+    dir = "tmpdir\u3042"
+    my_rm_rf dir
+
+    Dir.mkdir dir
+    File.write("#{dir}/\u3042.txt", "test_remove_entry_cjk_path")
+
+    remove_entry dir
+    assert_file_not_exist dir
+  end
+
   def test_remove_entry_secure
     check_singleton :remove_entry_secure
 
-- 
cgit v0.10.2


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

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