diff options
| author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2022-08-01 20:35:37 +0200 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2022-08-22 10:12:25 +0900 |
| commit | 70f69f85395f5735429cd45136d7de2742f08b72 (patch) | |
| tree | 3c0746f40f68f88b558dee9c25f2a327236e9873 | |
| parent | 9f3140a42e3542dce565a27135dceeb135a4e691 (diff) | |
[ruby/fileutils] Fix mkdir_p hanging on Windows when trying to create a file on a offline drive
https://github.com/ruby/fileutils/commit/9cc6a082d7
| -rw-r--r-- | lib/fileutils.rb | 2 | ||||
| -rw-r--r-- | test/fileutils/test_fileutils.rb | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 7eb66dda0c..8ae5266864 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -374,7 +374,7 @@ module FileUtils path = remove_trailing_slash(item) stack = [] - until File.directory?(path) + until File.directory?(path) || File.dirname(path) == path stack.push path path = File.dirname(path) end diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index e1e2a829c3..4afc8085ef 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -1098,6 +1098,14 @@ class TestFileUtils < Test::Unit::TestCase ensure Dir.rmdir(drive) if drive and File.directory?(drive) end + + def test_mkdir_p_offline_drive + offline_drive = ("A".."Z").to_a.reverse.find {|d| !File.exist?("#{d}:/") } + + assert_raise(Errno::ENOENT) { + mkdir_p "#{offline_drive}:/new_dir" + } + end end def test_mkdir_p_file_perm |
