Class: Bosh::Cli::Versions::VersionFileResolver
- Defined in:
- lib/cli/versions/version_file_resolver.rb
Instance Method Summary collapse
- #find_file(blobstore_id, sha1, desc) ⇒ Object
-
#initialize(storage, blobstore, tmpdir = Dir.tmpdir) ⇒ VersionFileResolver
constructor
A new instance of VersionFileResolver.
Constructor Details
#initialize(storage, blobstore, tmpdir = Dir.tmpdir) ⇒ VersionFileResolver
Returns a new instance of VersionFileResolver.
4 5 6 7 8 |
# File 'lib/cli/versions/version_file_resolver.rb', line 4 def initialize(storage, blobstore, tmpdir=Dir.tmpdir) @storage = storage @blobstore = blobstore @tmpdir = tmpdir end |
Instance Method Details
#find_file(blobstore_id, sha1, desc) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cli/versions/version_file_resolver.rb', line 10 def find_file(blobstore_id, sha1, desc) if @storage.has_file?(sha1) file_path = @storage.get_file(sha1) file_sha1 = Digest::SHA1.file(file_path).hexdigest if file_sha1 == sha1 return file_path end say("SHA1 '#{file_sha1}' of #{desc} does not match expected SHA1 '#{sha1}'".make_red) end if blobstore_id.nil? err("Cannot find #{desc}") end say("Downloading from blobstore (id=#{blobstore_id})...".make_green) tmp_file_path = File.join(@tmpdir, "bosh-tmp-file-#{SecureRandom.uuid}") begin File.open(tmp_file_path, 'wb') do |tmp_file| @blobstore.get(blobstore_id, tmp_file, sha1: sha1) end @storage.put_file(sha1, tmp_file_path) ensure FileUtils.rm(tmp_file_path, :force => true) end end |