avoid mkdir() race conditions - close #75

This commit is contained in:
Josh Holtrop 2018-12-11 22:13:33 -05:00
parent 432d221be2
commit 5720662b7c
2 changed files with 5 additions and 5 deletions

View File

@ -295,7 +295,7 @@ module Rscons
next if parts[i] == "" next if parts[i] == ""
subpath = File.join(*parts[0, i + 1]) subpath = File.join(*parts[0, i + 1])
unless File.exists?(subpath) unless File.exists?(subpath)
FileUtils.mkdir(subpath) FileUtils.mkdir_p(subpath)
@cache["directories"][subpath] = true @cache["directories"][subpath] = true
@dirty = true @dirty = true
end end

View File

@ -26,13 +26,13 @@ module Rscons
cache = build_from(_cache) cache = build_from(_cache)
expect(File).to receive(:exists?).with("one").and_return(true) expect(File).to receive(:exists?).with("one").and_return(true)
expect(File).to receive(:exists?).with("one/two").and_return(false) expect(File).to receive(:exists?).with("one/two").and_return(false)
expect(FileUtils).to receive(:mkdir).with("one/two") expect(FileUtils).to receive(:mkdir_p).with("one/two")
expect(File).to receive(:exists?).with("one/two/three").and_return(false) expect(File).to receive(:exists?).with("one/two/three").and_return(false)
expect(FileUtils).to receive(:mkdir).with("one/two/three") expect(FileUtils).to receive(:mkdir_p).with("one/two/three")
expect(File).to receive(:exists?).with("one").and_return(true) expect(File).to receive(:exists?).with("one").and_return(true)
expect(File).to receive(:exists?).with("one/two").and_return(true) expect(File).to receive(:exists?).with("one/two").and_return(true)
expect(File).to receive(:exists?).with("one/two/four").and_return(false) expect(File).to receive(:exists?).with("one/two/four").and_return(false)
expect(FileUtils).to receive(:mkdir).with("one/two/four") expect(FileUtils).to receive(:mkdir_p).with("one/two/four")
cache.mkdir_p("one/two/three") cache.mkdir_p("one/two/three")
cache.mkdir_p("one\\two\\four") cache.mkdir_p("one\\two\\four")
expect(cache.directories).to eq ["one/two", "one/two/three", "one/two/four"] expect(cache.directories).to eq ["one/two", "one/two/three", "one/two/four"]
@ -43,7 +43,7 @@ module Rscons
cache = build_from(_cache) cache = build_from(_cache)
expect(File).to receive(:exists?).with("/one").and_return(true) expect(File).to receive(:exists?).with("/one").and_return(true)
expect(File).to receive(:exists?).with("/one/two").and_return(false) expect(File).to receive(:exists?).with("/one/two").and_return(false)
expect(FileUtils).to receive(:mkdir).with("/one/two") expect(FileUtils).to receive(:mkdir_p).with("/one/two")
cache.mkdir_p("/one/two") cache.mkdir_p("/one/two")
expect(cache.directories).to eq ["/one/two"] expect(cache.directories).to eq ["/one/two"]
end end