lib/s3repo/repo.rb in s3repo-0.3.2 vs lib/s3repo/repo.rb in s3repo-0.3.3

- old
+ new

@@ -1,6 +1,7 @@ require 'basiccache' +require 'set' module S3Repo ## # Repo object, represents an Arch repo inside an S3 bucket class Repo < Base @@ -15,24 +16,27 @@ Dir.chdir(dir) { run "makepkg #{makepkg_flags}" } end end def add_packages(paths) - paths.each do |path| - key = File.basename(path) - sig_key, sig_path = [key, path].map { |x| x + '.sig' } - next if include? key - client.upload!(sig_key, sig_path) if ENV['S3REPO_SIGN_PACKAGES'] - client.upload!(key, path) - end + paths.select! { |path| upload_package(path) } metadata.add_packages(paths) end def remove_packages(packages) metadata.remove_packages(packages) end + def prune_packages + if orphans.empty? + puts 'No orphaned packages' + return + end + puts "Pruning packages: #{orphans.join(', ')}" + client.delete_objects(delete: { objects: orphans.map { |x| { key: x } } }) + end + def packages package_cache.cache { parse_packages } end def include?(key) @@ -43,9 +47,24 @@ refresh = !key.match(/\.pkg\.tar\.xz$/) file_cache.serve(key, refresh) end private + + def upload_package(path) + key = File.basename(path) + sig_key, sig_path = [key, path].map { |x| x + '.sig' } + return false if include? key + client.upload!(sig_key, sig_path) if ENV['S3REPO_SIGN_PACKAGES'] + client.upload!(key, path) + true + end + + def orphans + packages.map(&:key).reject do |x| + metadata.packages.include? x.reverse.split('-', 2).last.reverse + end + end def metadata @metadata ||= Metadata.new(client: client, file_cache: file_cache) end