1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
aamine 2003-12-11 10:15:54 +00:00
parent eec8dd6737
commit eb5a174119
2 changed files with 17 additions and 6 deletions

View file

@ -1,3 +1,10 @@
Thu Dec 11 19:08:02 2003 Minero Aoki <aamine@loveruby.net>
* 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 <aamine@loveruby.net> Thu Dec 11 18:49:30 2003 Minero Aoki <aamine@loveruby.net>
* lib/fileutils.rb: def m( arg ) -> def m(arg). * lib/fileutils.rb: def m( arg ) -> def m(arg).

View file

@ -170,14 +170,18 @@ module FileUtils
return *list if options[:noop] return *list if options[:noop]
mode = options[:mode] || (0777 & ~File.umask) 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 = [] stack = []
until File.directory?(dir) until path == stack.last # dirname("/")=="/", dirname("C:/")=="C:/"
stack.push dir stack.push path
dir = File.dirname(dir) path = File.dirname(path)
end end
stack.reverse_each do |n| stack.reverse_each do |path|
Dir.mkdir n, mode begin
Dir.mkdir path, mode
rescue Errno::EEXIST => err
raise unless File.directory?(path)
end
end end
end end