From 3261cfd88172a0ab86dcdffd4a8b0b5604970146 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 16 Feb 2017 08:42:22 +0000 Subject: fileutils.rb: do not make root * lib/fileutils.rb (FileUtils#mkdir_p): no need to make root directory which should be exist and cannot be made with mkdir recent Cygwin can make a directory contains a colon. [Bug #13214] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/fileutils.rb | 1 + test/fileutils/test_fileutils.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 660680f967..b24d6f4dcb 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -201,6 +201,7 @@ module FileUtils stack.push path path = File.dirname(path) end + stack.pop # root directory should exist stack.reverse_each do |dir| begin fu_mkdir dir, mode diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index 35e419e54d..f3b80d1fda 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -905,6 +905,24 @@ class TestFileUtils < Test::Unit::TestCase mkdir_p '/' end + if /mswin|mingw|cygwin/ =~ RUBY_PLATFORM + def test_mkdir_p_root + if /cygwin/ =~ RUBY_PLATFORM + tmpdir = `cygpath -ma .`.chomp + else + tmpdir = Dir.pwd + end + skip "No drive letter" unless /\A[a-z]:/i =~ tmpdir + drive = "./#{$&}" + assert_file_not_exist drive + mkdir_p "#{tmpdir}/none/dir" + assert_directory "none/dir" + assert_file_not_exist drive + ensure + Dir.rmdir(drive) if drive and File.directory?(drive) + end + end + def test_mkdir_p_file_perm mkdir_p 'tmp/tmp/tmp', :mode => 07777 assert_directory 'tmp/tmp/tmp' -- cgit v1.2.3