Sha256: 852891157a30062853dd877d7fca4c1cba400c1ff0342fcaf0d4357796010392

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

require 'fileutils'
require 'tempfile'

module S3Repo
  ##
  # Metadata object, represents repo's DB file
  class Metadata < Base
    def add_packages(paths)
      @db_path = nil
      paths.each do |path|
        puts "Adding #{File.basename(path)} to repo.db"
        run("repo-add #{db_path} #{path}")
      end
      update!
    end

    def remove_packages(packages)
      @db_path = nil
      packages.each do |package|
        puts "Removing #{package} from repo.db"
        run("repo-remove #{db_path} #{package}")
      end
      update!
    end

    def update!
      sign_db if @options[:sign_db]
      client.upload_file('repo.db', db_path)
      client.upload_file('repo.db.tar.xz', db_path)
    end

    def packages
      return @packages if @packages
      cmd = "bsdtar tf #{db_path}"
      @packages = run(cmd).split.map { |x| x.split('/').first }.uniq
    end

    private

    def signer
      @options[:signer] ||= Signer.new(@options)
    end

    def sign_db
      sig_path = signer.sign(db_path)
      client.upload_file('repo.db.sig', sig_path)
      client.upload_file('repo.db.tar.xz.sig', sig_path)
    end

    def db_path
      @db_path ||= file_cache.download('repo.db.tar.xz')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
s3repo-2.0.1 lib/s3repo/metadata.rb
s3repo-2.0.0 lib/s3repo/metadata.rb