From 5720662b7ceab7da44c2b8314da479e1bc9c51f2 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 11 Dec 2018 22:13:33 -0500 Subject: [PATCH] avoid mkdir() race conditions - close #75 --- lib/rscons/cache.rb | 2 +- spec/rscons/cache_spec.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/rscons/cache.rb b/lib/rscons/cache.rb index 81ae089..43fc997 100644 --- a/lib/rscons/cache.rb +++ b/lib/rscons/cache.rb @@ -295,7 +295,7 @@ module Rscons next if parts[i] == "" subpath = File.join(*parts[0, i + 1]) unless File.exists?(subpath) - FileUtils.mkdir(subpath) + FileUtils.mkdir_p(subpath) @cache["directories"][subpath] = true @dirty = true end diff --git a/spec/rscons/cache_spec.rb b/spec/rscons/cache_spec.rb index e1f5a86..e348eb7 100644 --- a/spec/rscons/cache_spec.rb +++ b/spec/rscons/cache_spec.rb @@ -26,13 +26,13 @@ module Rscons cache = build_from(_cache) expect(File).to receive(:exists?).with("one").and_return(true) 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(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/two").and_return(true) 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\\four") expect(cache.directories).to eq ["one/two", "one/two/three", "one/two/four"] @@ -43,7 +43,7 @@ module Rscons cache = build_from(_cache) expect(File).to receive(:exists?).with("/one").and_return(true) 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") expect(cache.directories).to eq ["/one/two"] end