Sha256: 992870c5a3a498e718780ae92f336a677ac468e5b7f5b13b1c5e4b2273a663df

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require 'basiccache'

module S3Repo
  ##
  # Repo object, represents an Arch repo inside an S3 bucket
  class Repo < Base
    def initialize(params = {})
      super
    end

    def build_packages(paths, makepkg_flags = '')
      paths.each do |path|
        dir = File.dirname(path)
        puts "Building #{File.basename(dir)}"
        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' }
        client.upload!(key, path) unless include?(key)
        client.upload!(sig_key, sig_path) if File.exist?(sig_path)
      end
      metadata.add_packages(paths)
    end

    def packages
      package_cache.cache { parse_packages }
    end

    def include?(key)
      !packages.find { |x| x.key == key }.nil?
    end

    def serve(key)
      refresh = !key.match(/\.pkg\.tar\.xz$/)
      file_cache.serve(key, refresh)
    end

    private

    def metadata
      @metadata ||= Metadata.new(client: client, file_cache: file_cache)
    end

    def package_cache
      @package_cache ||= BasicCache::TimeCache.new lifetime: 60
    end

    def parse_packages
      client.list_objects(bucket: bucket).contents.select do |x|
        x.key.match(/.*\.pkg\.tar\.xz$/)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
s3repo-0.1.7 lib/s3repo/repo.rb