class Akabei::Abs

Public Class Methods

new(path, repo_name) click to toggle source
# File lib/akabei/abs.rb, line 9
def initialize(path, repo_name)
  @path = Pathname.new(path)
  @repo_name = repo_name
end

Public Instance Methods

add(dir, builder) click to toggle source
# File lib/akabei/abs.rb, line 14
def add(dir, builder)
  builder.with_source_package(dir) do |srcpkg|
    Dir.mktmpdir do |tree|
      tree = Pathname.new(tree)
      root = tree.join(@repo_name)
      root.mkpath
      if @path.readable?
        ArchiveUtils.extract_all(@path, tree)
      end
      pkgname = detect_pkgname(srcpkg)
      FileUtils.rm_rf(root.join(pkgname))
      ArchiveUtils.extract_all(srcpkg, root)
      FileUtils.rm_f(@path)
      ArchiveUtils.archive_all(tree, @path, Archive::COMPRESSION_GZIP, Archive::FORMAT_TAR)
    end
  end
end
detect_pkgname(srcpkg) click to toggle source
# File lib/akabei/abs.rb, line 32
def detect_pkgname(srcpkg)
  ArchiveUtils.each_entry(srcpkg) do |entry|
    if entry.directory?
      if m = entry.pathname.match(%r{\A([^/]+)/\z})
        return m[1]
      end
    end
  end
  raise Error.new("Cannot detect pkgname from #{srcpkg}")
end
remove(package_name) click to toggle source
# File lib/akabei/abs.rb, line 43
def remove(package_name)
  unless @path.readable?
    raise Error.new("No such file: #{@path}")
  end

  Dir.mktmpdir do |tree|
    tree = Pathname.new(tree)
    ArchiveUtils.extract_all(@path, tree)
    root = tree.join(@repo_name)
    unless root.directory?
      raise Error.new("No such repository: #{@repo_name}")
    end
    FileUtils.rm_rf(root.join(package_name))
    ArchiveUtils.archive_all(tree, @path, Archive::COMPRESSION_GZIP, Archive::FORMAT_TAR)
  end
end