From eb5a1741196738df14f131c2e1b1a69412802964 Mon Sep 17 00:00:00 2001 From: aamine Date: Thu, 11 Dec 2003 10:15:54 +0000 Subject: [PATCH] * lib/fileutils.rb (mkdir_p): check if it is a directory after mkdir(2) instead of before mkdir(2), to avoid race condition. [ruby-talk:87730] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ lib/fileutils.rb | 16 ++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2595b57e7f..a1b32dd575 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Dec 11 19:08:02 2003 Minero Aoki + + * lib/fileutils.rb (mkdir_p): check if it is a directory after + mkdir(2) instead of before mkdir(2), to avoid race condition. + [ruby-talk:87730] + Refer: mkinstalldirs sh script, GNU mkdir(1) (coreutils 5.0) + Thu Dec 11 18:49:30 2003 Minero Aoki * lib/fileutils.rb: def m( arg ) -> def m(arg). diff --git a/lib/fileutils.rb b/lib/fileutils.rb index dea39c405b..eaa5434d39 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -170,14 +170,18 @@ module FileUtils return *list if options[:noop] mode = options[:mode] || (0777 & ~File.umask) - list.map {|n| File.expand_path(n) }.each do |dir| + list.map {|n| File.expand_path(n) }.each do |path| stack = [] - until File.directory?(dir) - stack.push dir - dir = File.dirname(dir) + until path == stack.last # dirname("/")=="/", dirname("C:/")=="C:/" + stack.push path + path = File.dirname(path) end - stack.reverse_each do |n| - Dir.mkdir n, mode + stack.reverse_each do |path| + begin + Dir.mkdir path, mode + rescue Errno::EEXIST => err + raise unless File.directory?(path) + end end end