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