Class: Akabei::Abs
- Inherits:
-
Object
- Object
- Akabei::Abs
- Defined in:
- lib/akabei/abs.rb
Instance Method Summary collapse
- #add(dir, builder) ⇒ Object
- #detect_pkgname(srcpkg) ⇒ Object
-
#initialize(path, repo_name) ⇒ Abs
constructor
A new instance of Abs.
- #remove(package_name) ⇒ Object
Constructor Details
#initialize(path, repo_name) ⇒ Abs
Returns a new instance of Abs.
9 10 11 12 |
# File 'lib/akabei/abs.rb', line 9 def initialize(path, repo_name) @path = Pathname.new(path) @repo_name = repo_name end |
Instance Method Details
#add(dir, builder) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# 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) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# 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) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 |