cookbook-omnifetch 0.10.1 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4df0a66a67a46dc690434e1bc71a7cf0020496214b51b6639236fa3a9843873a
4
- data.tar.gz: 3c1d54feae73211f2977a1c4b04fa5c294bd62aa0ace636e9b447175380b7b7b
3
+ metadata.gz: b6b7baff1c908f3ee02466f86ff7225a6a567006ed325313514d429eb07bddaa
4
+ data.tar.gz: a30c239d1ff4f032738cf9755226aff95e6f7df330c5119b367fa520306a9372
5
5
  SHA512:
6
- metadata.gz: 6dcfe66630ecb1af6dabce0f37b5d92454afe523ff22755ec4ebacdb047d6dbfc3fb17ad9cff5d1440d9ebca9d4811663054f344e65e45f81339e530a48250a6
7
- data.tar.gz: 94edbbeba3fc3d31a9789a1461cdf878073ed2bfb8d632a52e6ba1b16092331e680d7d720ea01ab2b0d069a70678c3ed20d849453fd1da42f80873535b822f88
6
+ metadata.gz: c7f11e46181d038e79d55e527ebc743b977ed012ad0630dbfe8f687bdc36c9638a0a7e70eb24feacc1fc2ef960cdd68f4cdbff55eea8d5bdd98c5f29f2b25962
7
+ data.tar.gz: 5ad4d570c3fe10fa6f30c055d8bb0d73dd24fc1a90c15fe804007bda3b9738780d0e87128ecfae2cb569e5bdba949ad3d2f3e48999e58c27b99dd970f4cae297
@@ -34,7 +34,8 @@ module CookbookOmnifetch
34
34
  #
35
35
  # @return [Boolean]
36
36
  def installed?
37
- install_path.exist?
37
+ # Always force a refresh of cache
38
+ false
38
39
  end
39
40
 
40
41
  def http_client
@@ -45,7 +45,8 @@ module CookbookOmnifetch
45
45
  #
46
46
  # @return [Boolean]
47
47
  def installed?
48
- install_path.exist?
48
+ # Always force a refresh of cache
49
+ false
49
50
  end
50
51
 
51
52
  def http_client
@@ -1,4 +1,5 @@
1
1
  require_relative "threaded_job_queue"
2
+ require "digest/md5"
2
3
 
3
4
  module CookbookOmnifetch
4
5
 
@@ -27,7 +28,7 @@ module CookbookOmnifetch
27
28
  next unless @metadata.key?(type.to_s)
28
29
 
29
30
  @metadata[type.to_s].each do |file|
30
- yield file["url"], file["path"]
31
+ yield file["url"], file["path"], file["checksum"]
31
32
  end
32
33
  end
33
34
  end
@@ -46,50 +47,58 @@ module CookbookOmnifetch
46
47
  end
47
48
 
48
49
  def install
49
- FileUtils.rm_rf(staging_path) # ensure we have a clean dir, just in case
50
- FileUtils.mkdir_p(staging_root) unless staging_root.exist?
51
- md = http_client.get(url_path)
52
-
53
- queue = ThreadedJobQueue.new
50
+ metadata = http_client.get(url_path)
51
+ clean_cache(metadata)
52
+ sync_cache(metadata)
53
+ end
54
54
 
55
- CookbookMetadata.new(md).files do |url, path|
56
- stage = staging_path.join(path)
57
- FileUtils.mkdir_p(File.dirname(stage))
55
+ # Removes files from cache that are not supposed to be there, based on
56
+ # files in metadata.
57
+ def clean_cache(metadata)
58
+ actual_file_list = Dir.glob(File.join(install_path, "**/*"))
59
+ expected_file_list = []
60
+ CookbookMetadata.new(metadata).files { |_, path, _| expected_file_list << File.join(install_path, path) }
61
+
62
+ extra_files = actual_file_list - expected_file_list
63
+ extra_files.each do |path|
64
+ if File.file?(path)
65
+ FileUtils.rm(path)
66
+ end
67
+ end
68
+ end
58
69
 
59
- queue << lambda do |_lock|
60
- http_client.streaming_request(url) do |tempfile|
61
- tempfile.close
62
- FileUtils.mv(tempfile.path, stage)
70
+ # Downloads any out-of-date files into installer cache, overwriting
71
+ # those that don't match the checksum provided the metadata @ url_path
72
+ def sync_cache(metadata)
73
+ queue = ThreadedJobQueue.new
74
+ CookbookMetadata.new(metadata).files do |url, path, checksum|
75
+ dest_path = File.join(install_path, path)
76
+ FileUtils.mkdir_p(File.dirname(dest_path))
77
+ if file_outdated?(dest_path, checksum)
78
+ queue << lambda do |_lock|
79
+ http_client.streaming_request(url) do |tempfile|
80
+ tempfile.close
81
+ FileUtils.mv(tempfile.path, dest_path)
82
+ end
63
83
  end
64
84
  end
65
85
  end
66
-
67
86
  queue.process(CookbookOmnifetch.chef_server_download_concurrency)
68
-
69
- FileUtils.mv(staging_path, install_path)
70
87
  end
71
88
 
72
- # The path where files are downloaded to. On certain platforms you have a
73
- # better chance of getting an atomic move if your temporary working
74
- # directory is on the same device/volume as the destination. To support
75
- # this, we use a staging directory located under the cache path under the
76
- # rather mild assumption that everything under the cache path is going to
77
- # be on one device.
89
+ # Check if a given file (at absolute path) is missing or does has a mismatched md5sum
78
90
  #
79
- # @return [Pathname]
80
- def staging_root
81
- Pathname.new(CookbookOmnifetch.cache_path).join(".cache_tmp", "metadata-installer")
82
- end
83
-
84
- def staging_path
85
- staging_root.join(staging_cache_key)
86
- end
87
-
88
- # Convert the URL to a safe name for a file and append our random slug.
89
- # This helps us avoid colliding in the case that there are multiple
90
- # processes installing the same cookbook at the same time.
91
- def staging_cache_key
92
- "#{url_path.gsub(/[^[:alnum:]]/, "_")}_#{slug}"
91
+ # @return [TrueClass, FalseClass]
92
+ def file_outdated?(path, expected_md5sum)
93
+ return true unless File.exist?(path)
94
+
95
+ md5 = Digest::MD5.new
96
+ File.open(path, "r") do |file|
97
+ while (chunk = file.read(1024))
98
+ md5.update chunk
99
+ end
100
+ end
101
+ md5.to_s != expected_md5sum
93
102
  end
94
103
  end
95
104
  end
@@ -1,3 +1,3 @@
1
1
  module CookbookOmnifetch
2
- VERSION = "0.10.1".freeze
2
+ VERSION = "0.11.1".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cookbook-omnifetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Winsor
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2020-08-21 00:00:00.000000000 Z
16
+ date: 2020-08-31 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: mixlib-archive
@@ -74,7 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - ">="
76
76
  - !ruby/object:Gem::Version
77
- version: '2.4'
77
+ version: '2.5'
78
78
  required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="