diff options
author | sersut <serdar@opscode.com> | 2013-07-29 18:03:04 +0300 |
---|---|---|
committer | sersut <serdar@opscode.com> | 2013-07-29 18:03:04 +0300 |
commit | 6ac4b7ebdb758cf45bfde6e60f7c63f6abd36108 (patch) | |
tree | 44f60eed4b08500d8edffd658b2dfc11ea2a6980 | |
parent | 49dcd0e06a88602362901ff97005d3805428da84 (diff) | |
download | chef-6ac4b7ebdb758cf45bfde6e60f7c63f6abd36108.tar.gz |
Fix CHEF-4419 by appending a drive letter from the current working directory to the path if it starts with '/' in the most common code path we're encountering this issue.
-rw-r--r-- | lib/chef/win32/api/file.rb | 7 | ||||
-rw-r--r-- | spec/support/shared/functional/file_resource.rb | 37 |
2 files changed, 44 insertions, 0 deletions
diff --git a/lib/chef/win32/api/file.rb b/lib/chef/win32/api/file.rb index 49088c67ae..afa746efce 100644 --- a/lib/chef/win32/api/file.rb +++ b/lib/chef/win32/api/file.rb @@ -471,6 +471,13 @@ BOOL WINAPI DeviceIoControl( # ensures the handle is closed on exit of the block def file_search_handle(path, &block) begin + # Workaround for CHEF-4419: + # Make sure paths starting with "/" has a drive letter + # assigned from the current working diretory. + # Note: In chef 11.8 and beyond this issue will be fixed with a + # broader fix to map all the paths starting with "/" to + # SYSTEM_DRIVE on windows. + path = ::File.expand_path(path) if path.start_with? "/" path = encode_path(path) find_data = WIN32_FIND_DATA.new handle = FindFirstFileW(path, find_data) diff --git a/spec/support/shared/functional/file_resource.rb b/spec/support/shared/functional/file_resource.rb index 30f012bb0d..bab421d18d 100644 --- a/spec/support/shared/functional/file_resource.rb +++ b/spec/support/shared/functional/file_resource.rb @@ -895,6 +895,43 @@ shared_examples_for "a configured file resource" do end end + # Regression test for http://tickets.opscode.com/browse/CHEF-4419 + context "when the path starts with '/' and target file exists", :windows_only do + let(:path) do + File.join(test_file_dir[2..test_file_dir.length], make_tmpname(file_base)) + end + + before do + File.open(path, "wb") { |f| f.print expected_content } + now = Time.now.to_i + File.utime(now - 9000, now - 9000, path) + + @expected_mtime = File.stat(path).mtime + @expected_checksum = sha256_checksum(path) + end + + describe ":create action should run without any updates" do + before do + # Assert starting state is as expected + File.should exist(path) + sha256_checksum(path).should == @expected_checksum + resource.run_action(:create) + end + + it "does not overwrite the original when the :create action is run" do + sha256_checksum(path).should == @expected_checksum + end + + it "does not update the mtime of the file when the :create action is run" do + File.stat(path).mtime.should == @expected_mtime + end + + it "is not marked as updated by last action" do + resource.should_not be_updated_by_last_action + end + end + end + end shared_context Chef::Resource::File do |