We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dbe9f64 commit a226b78Copy full SHA for a226b78
1 file changed
chef/lib/chef/cache/file_cache_by_checksum.rb
@@ -0,0 +1,35 @@
1
+class Chef
2
+ class Cache
3
+ class FileCacheByChecksum
4
+ attr_reader :basedir
5
+
6
+ def initialize(basedir = Chef::Config[:file_cache_path])
7
+ @basedir = basedir
8
9
10
+ end
11
12
+ # returns path
13
+ def get_path(checksum)
14
+ path = checksum_path(checksum)
15
16
+ File.exists?(path) ? path : nil
17
18
19
+ # path = path to tempfile as input
20
+ # returns destination path
21
+ def put(checksum, src_path)
22
+ dest_path = checksum_path(checksum)
23
+ FileUtils.mkdir_p(File.dirname(dest_path))
24
25
+ FileUtils.cp(src_path, dest_path)
26
27
+ dest_path
28
29
30
+ def checksum_path(checksum)
31
+ File.join(@basedir, checksum[0..1], checksum)
32
33
34
35
+end
0 commit comments