From ea30b0b5eea8aa32453c3bf5e6f69177f3aa1adc Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 15 Apr 2014 14:15:32 -0400 Subject: [PATCH] Fix Cache#mkdir_p to handle absolute paths - fix #5 --- lib/rscons/cache.rb | 1 + spec/rscons/cache_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/rscons/cache.rb b/lib/rscons/cache.rb index a9e240e..28dcfa8 100644 --- a/lib/rscons/cache.rb +++ b/lib/rscons/cache.rb @@ -181,6 +181,7 @@ module Rscons def mkdir_p(path) parts = path.split(/[\\\/]/) parts.each_index do |i| + next if parts[i] == "" subpath = File.join(*parts[0, i + 1]) unless File.exists?(subpath) FileUtils.mkdir(subpath) diff --git a/spec/rscons/cache_spec.rb b/spec/rscons/cache_spec.rb index 5b30a8c..1f72003 100644 --- a/spec/rscons/cache_spec.rb +++ b/spec/rscons/cache_spec.rb @@ -225,6 +225,16 @@ module Rscons cache.mkdir_p("one\\two\\four") cache.directories.should == ["one/two", "one/two/three", "one/two/four"] end + + it "handles absolute paths" do + _cache = {} + cache = build_from(_cache) + File.should_receive(:exists?).with("/one").and_return(true) + File.should_receive(:exists?).with("/one/two").and_return(false) + FileUtils.should_receive(:mkdir).with("/one/two") + cache.mkdir_p("/one/two") + cache.directories.should == ["/one/two"] + end end describe "#directories" do