lib/autobuild/import/tar.rb in autobuild-1.0 vs lib/autobuild/import/tar.rb in autobuild-1.0.1
- old
+ new
@@ -1,5 +1,6 @@
+require 'autobuild/importer'
require 'open-uri'
module Autobuild
class TarImporter < Importer
# The tarball is not compressed
@@ -75,17 +76,17 @@
end
# Sets the source URL and update +cachefile+ and +mode+ attributes accordingly.
def url=(url)
@url = URI.parse(url)
- raise ConfigException, "invalid URL #{url}" unless VALID_URI_SCHEMES.include?(url.scheme)
+ raise ConfigException, "invalid URL #{@url}" unless VALID_URI_SCHEMES.include?(@url.scheme)
@mode = TarImporter.url_to_mode(url)
- if url.scheme == 'file'
- @cachefile = url
+ if @url.scheme == 'file'
+ @cachefile = @url.path
else
- @cachefile = File.join(cachedir, File.basename(url.path))
+ @cachefile = File.join(cachedir, File.basename(@url.path))
end
end
# The source URL
attr_reader :url
@@ -93,14 +94,18 @@
attr_reader :cachefile
# The unpack mode. One of Bzip, Gzip or Plain
attr_reader :mode
# The directory in which remote files are cached
def cachedir; @options[:cachedir] end
+ # The directory contained in the tar file
+ def tardir; @options[:tardir] end
# Creates a new importer which downloads +url+ in +cachedir+ and unpacks it. The following options
# are allowed:
# [:cachedir] the cache directory. Defaults to "#{Autobuild.prefix}/cache"
+ # [:tardir] the directory contained in the tar file. If set, the importer will rename that directory
+ # to make it match Package#srcdir
def initialize(url, options)
@options = options.dup
@options[:cachedir] ||= "#{Autobuild.prefix}/cache"
self.url = url
end
@@ -115,12 +120,15 @@
update_cache
base_dir = File.dirname(package.srcdir)
FileUtils.mkdir_p base_dir
cmd = [ 'tar', "x#{TAR_OPTION[mode]}f", cachefile, '-C', base_dir ]
-
+
Subprocess.run(package.name, :import, *cmd)
+ if tardir
+ File.mv File.join(base_dir, tardir), package.srcdir
+ end
rescue OpenURI::HTTPError
raise Autobuild::Exception.new(package.name, :import)
rescue SubcommandFailed
FileUtils.rm_f cachefile
@@ -128,10 +136,10 @@
end
end
# Creates an importer which downloads a tarball from +source+ and unpacks
# it. The allowed values in +options+ are described in TarImporter.new.
- def self.tar(source, options)
+ def self.tar(source, options = {})
TarImporter.new(source, options)
end
end