From 32ef13c2e089904ceb1523f6bb7498699f0beea0 Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Wed, 17 Apr 2024 13:21:26 -0500 Subject: [PATCH] optimize fetch to use local download if source is already downloaded and can be verified, skip downloading again. --- lib/vanagon/component/source/http.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/vanagon/component/source/http.rb b/lib/vanagon/component/source/http.rb index 05097b1d..5b2fddd0 100644 --- a/lib/vanagon/component/source/http.rb +++ b/lib/vanagon/component/source/http.rb @@ -82,6 +82,13 @@ 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) + begin + return if verify + rescue RuntimeError, Errno::ENOENT + remove_instance_variable(:@file) + end + @file = download(@url) end