* 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:
parent
482f0e6b97
commit
cef3f2ebd4
@ -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>
|
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.
|
* dir.c (is_hfs): use the file descriptor instead of a path.
|
||||||
|
@ -154,6 +154,11 @@ module FileUtils
|
|||||||
end
|
end
|
||||||
module_function :uptodate?
|
module_function :uptodate?
|
||||||
|
|
||||||
|
def remove_tailing_slash(dir)
|
||||||
|
dir == '/' ? dir : dir.chomp(?/)
|
||||||
|
end
|
||||||
|
private_module_function :remove_tailing_slash
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: mode noop verbose
|
# 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]
|
fu_output_message "mkdir -p #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose]
|
||||||
return *list if options[:noop]
|
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
|
# optimize for the most common case
|
||||||
begin
|
begin
|
||||||
fu_mkdir path, options[:mode]
|
fu_mkdir path, options[:mode]
|
||||||
@ -237,7 +242,7 @@ module FileUtils
|
|||||||
OPT_TABLE['makedirs'] = [:mode, :noop, :verbose]
|
OPT_TABLE['makedirs'] = [:mode, :noop, :verbose]
|
||||||
|
|
||||||
def fu_mkdir(path, mode) #:nodoc:
|
def fu_mkdir(path, mode) #:nodoc:
|
||||||
path = path.chomp(?/)
|
path = remove_tailing_slash(path)
|
||||||
if mode
|
if mode
|
||||||
Dir.mkdir path, mode
|
Dir.mkdir path, mode
|
||||||
File.chmod mode, path
|
File.chmod mode, path
|
||||||
|
@ -758,6 +758,10 @@ class TestFileUtils
|
|||||||
assert_directory 'tmp/tmp'
|
assert_directory 'tmp/tmp'
|
||||||
assert_equal 0700, (File.stat('tmp/tmp').mode & 0777) if have_file_perm?
|
assert_equal 0700, (File.stat('tmp/tmp').mode & 0777) if have_file_perm?
|
||||||
Dir.rmdir 'tmp/tmp'
|
Dir.rmdir 'tmp/tmp'
|
||||||
|
|
||||||
|
assert_raise(Errno::EISDIR) {
|
||||||
|
mkdir '/'
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mkdir_file_perm
|
def test_mkdir_file_perm
|
||||||
@ -831,6 +835,8 @@ class TestFileUtils
|
|||||||
# (rm(1) try to chdir to parent directory, it fails to remove directory.)
|
# (rm(1) try to chdir to parent directory, it fails to remove directory.)
|
||||||
Dir.rmdir 'tmp/tmp'
|
Dir.rmdir 'tmp/tmp'
|
||||||
Dir.rmdir 'tmp'
|
Dir.rmdir 'tmp'
|
||||||
|
|
||||||
|
mkdir_p '/'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mkdir_p_file_perm
|
def test_mkdir_p_file_perm
|
||||||
|
Loading…
x
Reference in New Issue
Block a user