summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2015-11-12 10:10:04 +0000
committerThom May <thom@may.lt>2015-11-12 10:10:04 +0000
commit880f744ce9f6cef12b7bdbd746641b87a27f5809 (patch)
tree5c89d827589f27d8bc5173ac161fb001f4081f6c /lib/chef
parent1486782645f7e8eb2fcd10116b2eacd2af594c87 (diff)
parent7b9726f50abaf05ddb2c4ab215b9e265138ca063 (diff)
downloadchef-880f744ce9f6cef12b7bdbd746641b87a27f5809.tar.gz
Merge pull request #3991 from chef/jdm/remote-file-sha2
Modify remote_file cache_control_data to use sha256 for its name
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/provider/remote_file/cache_control_data.rb41
1 files changed, 37 insertions, 4 deletions
diff --git a/lib/chef/provider/remote_file/cache_control_data.rb b/lib/chef/provider/remote_file/cache_control_data.rb
index f9b729362c..3f39dac625 100644
--- a/lib/chef/provider/remote_file/cache_control_data.rb
+++ b/lib/chef/provider/remote_file/cache_control_data.rb
@@ -145,18 +145,51 @@ class Chef
end
def load_json_data
- Chef::FileCache.load("remote_file/#{sanitized_cache_file_basename}")
+ path = sanitized_cache_file_path(sanitized_cache_file_basename)
+ if Chef::FileCache.has_key?(path)
+ Chef::FileCache.load(path)
+ else
+ old_path = sanitized_cache_file_path(sanitized_cache_file_basename_md5)
+ if Chef::FileCache.has_key?(old_path)
+ # We found an old cache control data file. We started using sha256 instead of md5
+ # to name these. Upgrade the file to the new name.
+ Chef::Log.debug("Found old cache control data file at #{old_path}. Moving to #{path}.")
+ Chef::FileCache.load(old_path).tap do |data|
+ Chef::FileCache.store(path, data)
+ Chef::FileCache.delete(old_path)
+ end
+ else
+ raise Chef::Exceptions::FileNotFound
+ end
+ end
end
- def sanitized_cache_file_basename
+ def sanitized_cache_file_path(basename)
+ "remote_file/#{basename}"
+ end
+
+ def scrubbed_uri
# Scrub and truncate in accordance with the goals of keeping the name
# human-readable but within the bounds of local file system
# path length limits
- scrubbed_uri = uri.gsub(/\W/, '_')[0..63]
+ uri.gsub(/\W/, '_')[0..63]
+ end
+
+ def sanitized_cache_file_basename
+ uri_sha2 = Chef::Digester.instance.generate_checksum(StringIO.new(uri))
+ cache_file_basename(uri_sha2[0,32])
+ end
+
+
+ def sanitized_cache_file_basename_md5
+ # Old way of creating the file basename
uri_md5 = Chef::Digester.instance.generate_md5_checksum(StringIO.new(uri))
- "#{scrubbed_uri}-#{uri_md5}.json"
+ cache_file_basename(uri_md5)
end
+ def cache_file_basename(checksum)
+ "#{scrubbed_uri}-#{checksum}.json"
+ end
end
end
end