Skip to content

Commit

Permalink
windows path fix for CHEF-4472
Browse files Browse the repository at this point in the history
  • Loading branch information
bastien-jove-cbp authored and btm committed Apr 10, 2014
1 parent 2404f19 commit 07f6316
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/chef/provider/remote_file/local_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ def initialize(uri, new_resource, current_resource)
@new_resource = new_resource
@uri = uri
end

# CHEF-4472: Remove the leading slash from windows paths that we receive from a file:// URI
def fix_windows_path(path)
path.gsub(/^\/([a-zA-Z]:)/,'\1')
end

# Fetches the file at uri, returning a Tempfile-like File handle
def fetch
Chef::Platform.windows? ? source_path = fix_windows_path(uri.path) : source_path = uri.path
tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile
Chef::Log.debug("#{new_resource} staging #{uri.path} to #{tempfile.path}")
FileUtils.cp(uri.path, tempfile.path)
FileUtils.cp(source_path, tempfile.path)
tempfile.close if tempfile
tempfile
end
Expand Down
23 changes: 23 additions & 0 deletions spec/unit/provider/remote_file/local_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@
let(:new_resource) { Chef::Resource::RemoteFile.new("local file backend test (new_resource)") }
let(:current_resource) { Chef::Resource::RemoteFile.new("local file backend test (current_resource)") }
subject(:fetcher) { Chef::Provider::RemoteFile::LocalFile.new(uri, new_resource, current_resource) }

context "when parsing source path" do
describe "when given local unix path" do
let(:uri) { URI.parse("file:///nyan_cat.png") }
it "returns a correct unix path" do
fetcher.fix_windows_path(uri.path).should == "/nyan_cat.png"
end
end

describe "when given local windows path" do
let(:uri) { URI.parse("file:///z:/windows/path/file.txt") }
it "returns a valid windows local path" do
fetcher.fix_windows_path(uri.path).should == "z:/windows/path/file.txt"
end
end

describe "when given unc windows path" do
let(:uri) { URI.parse("file:////server/share/windows/path/file.txt") }
it "returns a valid windows unc path" do
fetcher.fix_windows_path(uri.path).should == "//server/share/windows/path/file.txt"
end
end
end

context "when first created" do

Expand Down

0 comments on commit 07f6316

Please sign in to comment.