Fix Cache#mkdir_p to handle absolute paths - fix #5

This commit is contained in:
Josh Holtrop 2014-04-15 14:15:32 -04:00
parent 5a0d80b781
commit ea30b0b5ee
2 changed files with 11 additions and 0 deletions

View File

@ -181,6 +181,7 @@ module Rscons
def mkdir_p(path) def mkdir_p(path)
parts = path.split(/[\\\/]/) parts = path.split(/[\\\/]/)
parts.each_index do |i| parts.each_index do |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(subpath)

View File

@ -225,6 +225,16 @@ module Rscons
cache.mkdir_p("one\\two\\four") cache.mkdir_p("one\\two\\four")
cache.directories.should == ["one/two", "one/two/three", "one/two/four"] cache.directories.should == ["one/two", "one/two/three", "one/two/four"]
end 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 end
describe "#directories" do describe "#directories" do