Skip to content

Commit

Permalink
optimize fetch to use local download
Browse files Browse the repository at this point in the history
if source is already downloaded and can be verified, skip downloading again.
  • Loading branch information
h0tw1r3 committed Apr 17, 2024

Verified

This commit was signed with the committer’s verified signature.
Bot-wxt1221 Bot_wxt1221
1 parent e344e9b commit 8c102fa
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/vanagon/component/source/http.rb
Original file line number Diff line number Diff line change
@@ -82,6 +82,16 @@ def initialize(url, sum:, workdir:, sum_type:, **options)
# Download the source from the url specified. Sets the full path to the
# file as @file and the @extension for the file as a side effect.
def fetch
@file = File.basename(URI.parse(@url).path)
if File.exists?(File.join(workdir, file))
begin
return if verify
rescue RuntimeError, Errno::ENOENT
# ignore invalid "cached" file
end
end
remove_instance_variable(:@file)

@file = download(@url)
end

@@ -93,9 +103,13 @@ def file
#
# @raise [RuntimeError] an exception is raised if the sum does not match the sum of the file
def verify
return true if @verified

VanagonLogger.info "Verifying file: #{file} against sum: '#{sum}'"
actual = get_sum(File.join(workdir, file), sum_type)
return true if sum == actual

@verified = (sum == actual)
return true if @verified

fail "Unable to verify '#{File.join(workdir, file)}': #{sum_type} mismatch (expected '#{sum}', got '#{actual}')"
end

0 comments on commit 8c102fa

Please sign in to comment.