From cef3f2ebd45c10823a60a70448b8400accbdaf38 Mon Sep 17 00:00:00 2001 From: ayumin Date: Mon, 3 Jun 2013 14:20:15 +0000 Subject: * 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 --- ChangeLog | 6 ++++++ lib/fileutils.rb | 9 +++++++-- test/fileutils/test_fileutils.rb | 6 ++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c00ba076ec..6189c92f6d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Jun 3 23:11:19 2013 Ayumu AIZAWA + + * 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 * dir.c (is_hfs): use the file descriptor instead of a path. diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 8daf923c78..7f14f138d9 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -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 diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index 54742d1d18..b03c9ba2be 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -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 -- cgit v1.2.3