Skip to content

Commit a226b78

Browse files
Tim Hinderliterdanielsdeleo
authored andcommitted
new class, FileCacheByChecksum used for local cookbook caching
1 parent dbe9f64 commit a226b78

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
end
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+
end
29+
30+
def checksum_path(checksum)
31+
File.join(@basedir, checksum[0..1], checksum)
32+
end
33+
end
34+
end
35+
end

0 commit comments

Comments
 (0)