Commit b3cba04b authored by satmandu's avatar satmandu Committed by GitHub

Crew Cache Cleanup (#5694)

* Crew Cache Cleanup

* Only cache package if downloaded

* Make output prettier.

* Change all  .to_s == '' to .to_s.empty

* Add ?
parent 1f091a49
...@@ -578,36 +578,58 @@ def download ...@@ -578,36 +578,58 @@ def download
case File.basename(filename) case File.basename(filename)
# Sources that download with curl # Sources that download with curl
when /\.zip$/i, /\.(tar(\.(gz|bz2|xz|lz))?|tgz|tbz|txz)$/i, /\.deb$/i when /\.zip$/i, /\.(tar(\.(gz|bz2|xz|lz))?|tgz|tbz|txz)$/i, /\.deb$/i
# Recall file from cache if requeseted # Recall file from cache if requested
if CREW_CACHE_ENABLED if CREW_CACHE_ENABLED
puts "Looking for archive in cache".orange if @opt_verbose
cachefile = CREW_CACHE_DIR + filename cachefile = CREW_CACHE_DIR + filename
if File.file?(cachefile) if ! File.exist?(cachefile)
puts 'Cannot find cached archive. 😔 Will download.'.lightred
cachefile = ''
else
puts "Archive file exists in cache".lightgreen if @opt_verbose
if Digest::SHA256.hexdigest( File.read(cachefile) ) == sha256sum then if Digest::SHA256.hexdigest( File.read(cachefile) ) == sha256sum then
FileUtils.cp cachefile, CREW_BREW_DIR, verbose: @fileutils_verbose begin
puts "Archive found in cache".lightgreen # Hard link cached file if possible.
return {source: source, filename: filename} FileUtils.ln cachefile, CREW_BREW_DIR, verbose: @fileutils_verbose
puts "Archive hard linked from cache".green if @opt_verbose
rescue
# Copy cached file if hard link fails.
FileUtils.cp cachefile, CREW_BREW_DIR, verbose: @fileutils_verbose
puts "Archive copied from cache".green if @opt_verbose
end
puts "Archive found in cache".lightgreen
return {source: source, filename: filename}
else else
puts 'Cached archive checksum mismatch. :/ Will download.'.lightred puts 'Cached archive checksum mismatch. :/ Will download.'.lightred
cachefile = ''
end end
puts 'Cannot find cached archive. :/ Will download.'.lightred
end end
end end
# Download file if not cached # Download file if not cached.
system "#{CURL} --retry 3 -#{@verbose}#LC - --insecure \'#{url}\' --output #{filename}" system "#{CURL} --retry 3 -#{@verbose}#LC - --insecure \'#{url}\' --output #{filename}"
abort 'Checksum mismatch. :/ Try again.'.lightred unless abort 'Checksum mismatch. :/ Try again.'.lightred unless
Digest::SHA256.hexdigest( File.read(filename) ) == sha256sum Digest::SHA256.hexdigest( File.read(filename) ) == sha256sum
puts 'Archive downloaded.'.lightgreen puts 'Archive downloaded.'.lightgreen
# Stow file in cache if requested # Stow file in cache if requested (and if file is not from cache).
if CREW_CACHE_ENABLED if CREW_CACHE_ENABLED and cachefile.to_s.empty?
FileUtils.cp filename, CREW_CACHE_DIR, verbose: @fileutils_verbose begin
puts 'Archive cached.'.lightgreen # Hard link to cache if possible.
FileUtils.ln filename, CREW_CACHE_DIR, verbose: @fileutils_verbose
puts "Archive hard linked to cache".green if @opt_verbose
rescue
# Copy to cache if hard link fails.
FileUtils.cp filename, CREW_CACHE_DIR, verbose: @fileutils_verbose
puts "Archive copied to cache".green if @opt_verbose
end
puts 'Archive copied to cache.'.lightgreen
end end
return {source: source, filename: filename}
# Sources that download with git # Sources that download with git
when /\.git$/i when /\.git$/i
# Recall repository from cache if requested # Recall repository from cache if requested
if CREW_CACHE_ENABLED if CREW_CACHE_ENABLED
cachefile = CREW_CACHE_DIR + '/' + filename + '.tar.xz' cachefile = CREW_CACHE_DIR + filename + '.tar.xz'
if File.file?(cachefile) if File.file?(cachefile)
if system "sha256sum -c #{cachefile}.sha256" if system "sha256sum -c #{cachefile}.sha256"
FileUtils.mkdir @extract_dir FileUtils.mkdir @extract_dir
......
# Defines common constants used in different parts of crew # Defines common constants used in different parts of crew
CREW_VERSION = '1.8.10' CREW_VERSION = '1.8.11'
ARCH_ACTUAL = `uname -m`.strip ARCH_ACTUAL = `uname -m`.strip
# This helps with virtualized builds on aarch64 machines # This helps with virtualized builds on aarch64 machines
...@@ -10,7 +10,7 @@ ARCH = if ARCH_ACTUAL == 'armv8l' then 'armv7l' else ARCH_ACTUAL end ...@@ -10,7 +10,7 @@ ARCH = if ARCH_ACTUAL == 'armv8l' then 'armv7l' else ARCH_ACTUAL end
ARCH_LIB = if ARCH == 'x86_64' then 'lib64' else 'lib' end ARCH_LIB = if ARCH == 'x86_64' then 'lib64' else 'lib' end
LIBC_VERSION = if File.exist? "/#{ARCH_LIB}/libc-2.27.so" then '2.27' else '2.23' end LIBC_VERSION = if File.exist? "/#{ARCH_LIB}/libc-2.27.so" then '2.27' else '2.23' end
if ENV['CREW_PREFIX'].to_s == '' if ENV['CREW_PREFIX'].to_s.empty?
CREW_PREFIX = '/usr/local' CREW_PREFIX = '/usr/local'
else else
CREW_PREFIX = ENV['CREW_PREFIX'] CREW_PREFIX = ENV['CREW_PREFIX']
...@@ -29,17 +29,19 @@ CREW_DEST_PREFIX = CREW_DEST_DIR + CREW_PREFIX ...@@ -29,17 +29,19 @@ CREW_DEST_PREFIX = CREW_DEST_DIR + CREW_PREFIX
CREW_DEST_LIB_PREFIX = CREW_DEST_DIR + CREW_LIB_PREFIX CREW_DEST_LIB_PREFIX = CREW_DEST_DIR + CREW_LIB_PREFIX
CREW_DEST_MAN_PREFIX = CREW_DEST_DIR + CREW_MAN_PREFIX CREW_DEST_MAN_PREFIX = CREW_DEST_DIR + CREW_MAN_PREFIX
if ENV['CREW_PREFIX'].to_s == '' if ENV['CREW_PREFIX'].to_s.empty?
HOME = ENV['HOME'] HOME = ENV['HOME']
else else
HOME = CREW_PREFIX + ENV['HOME'] HOME = CREW_PREFIX + ENV['HOME']
end end
if ENV['CREW_CACHE_DIR'].to_s == '' # File.join ensures a trailing slash if one does not exist.
CREW_CACHE_DIR = HOME + '/.cache/crewcache' if ENV['CREW_CACHE_DIR'].to_s.empty?
CREW_CACHE_DIR = File.join(HOME + '/.cache/crewcache', '')
else else
CREW_CACHE_DIR = ENV['CREW_CACHE_DIR'] CREW_CACHE_DIR = File.join(ENV['CREW_CACHE_DIR'], '')
end end
FileUtils.mkdir_p CREW_CACHE_DIR unless Dir.exist? CREW_CACHE_DIR FileUtils.mkdir_p CREW_CACHE_DIR unless Dir.exist? CREW_CACHE_DIR
CREW_CACHE_ENABLED = ENV['CREW_CACHE_ENABLED'] CREW_CACHE_ENABLED = ENV['CREW_CACHE_ENABLED']
...@@ -47,7 +49,7 @@ CREW_CACHE_ENABLED = ENV['CREW_CACHE_ENABLED'] ...@@ -47,7 +49,7 @@ CREW_CACHE_ENABLED = ENV['CREW_CACHE_ENABLED']
CREW_DEST_HOME = CREW_DEST_DIR + HOME CREW_DEST_HOME = CREW_DEST_DIR + HOME
# Set CREW_NPROC from environment variable or `nproc` # Set CREW_NPROC from environment variable or `nproc`
if ENV["CREW_NPROC"].to_s == '' if ENV["CREW_NPROC"].to_s.empty?
CREW_NPROC = `nproc`.strip CREW_NPROC = `nproc`.strip
else else
CREW_NPROC = ENV["CREW_NPROC"] CREW_NPROC = ENV["CREW_NPROC"]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment