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