* lib/fileutils.rb: fix behavior when mkdir/mkdir_p accepted "/".

* test/fileutils/test_fileutils.rb: add test for above change.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ayumin 2013-06-03 14:20:15 +00:00
parent 482f0e6b97
commit cef3f2ebd4
3 changed files with 19 additions and 2 deletions

View File

@ -1,3 +1,9 @@
Mon Jun 3 23:11:19 2013 Ayumu AIZAWA <ayumu.aizawa@gmail.com>
* lib/fileutils.rb: fix behavior when mkdir/mkdir_p accepted "/".
* test/fileutils/test_fileutils.rb: add test for above change.
Patched by Mitsunori Komatsu. [GH-319]
Mon Jun 3 19:02:20 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* dir.c (is_hfs): use the file descriptor instead of a path.

View File

@ -154,6 +154,11 @@ module FileUtils
end
module_function :uptodate?
def remove_tailing_slash(dir)
dir == '/' ? dir : dir.chomp(?/)
end
private_module_function :remove_tailing_slash
#
# Options: mode noop verbose
#
@ -200,7 +205,7 @@ module FileUtils
fu_output_message "mkdir -p #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose]
return *list if options[:noop]
list.map {|path| path.chomp(?/) }.each do |path|
list.map {|path| remove_tailing_slash(path)}.each do |path|
# optimize for the most common case
begin
fu_mkdir path, options[:mode]
@ -237,7 +242,7 @@ module FileUtils
OPT_TABLE['makedirs'] = [:mode, :noop, :verbose]
def fu_mkdir(path, mode) #:nodoc:
path = path.chomp(?/)
path = remove_tailing_slash(path)
if mode
Dir.mkdir path, mode
File.chmod mode, path

View File

@ -758,6 +758,10 @@ class TestFileUtils
assert_directory 'tmp/tmp'
assert_equal 0700, (File.stat('tmp/tmp').mode & 0777) if have_file_perm?
Dir.rmdir 'tmp/tmp'
assert_raise(Errno::EISDIR) {
mkdir '/'
}
end
def test_mkdir_file_perm
@ -831,6 +835,8 @@ class TestFileUtils
# (rm(1) try to chdir to parent directory, it fails to remove directory.)
Dir.rmdir 'tmp/tmp'
Dir.rmdir 'tmp'
mkdir_p '/'
end
def test_mkdir_p_file_perm