The tarball is compressed using bzip
The tarball is compressed with gzip
The tarball is not compressed
Known URI schemes for url
Not a tarball but a zip
The local file (either a downloaded file if url is not local,
or url itself)
The source URL
Returns the unpack mode from the file name
# File lib/autobuild/import/archive.rb, line 35 def self.filename_to_mode(filename) case filename when /\.zip$/; Zip when /\.tar$/; Plain when /\.tar\.gz$|\.tgz$/; Gzip when /\.bz2$/; Bzip else raise "unknown file type '#{filename}'" end end
Creates a new importer which downloads url in
cachedir and unpacks it. The following options are allowed:
the cache directory. Defaults to “#{Autobuild.prefix}/cache”
the directory contained in the archive file. If set,
the importer will rename that directory to make it match Package#srcdir
the archive does not have the custom archive
subdirectory.
# File lib/autobuild/import/archive.rb, line 171 def initialize(url, options) super(options) if !@options.has_key?(:update_cached_file) @options[:update_cached_file] = false end @options[:cachedir] ||= "#{Autobuild.prefix}/cache" @url = URI.parse(url) if !VALID_URI_SCHEMES.include?(@url.scheme) raise ConfigException, "invalid URL #{@url} (local files must be prefixed with file://)" end filename = options[:filename] || File.basename(url).gsub(/\?.*/, '') @mode = options[:mode] || ArchiveImporter.filename_to_mode(filename) if @url.scheme == 'file' @cachefile = @url.path else @cachefile = File.join(cachedir, filename) end end
The directory contained in the archive. If not set, we assume that it is the same than the source dir
# File lib/autobuild/import/archive.rb, line 154 def archive_dir; @options[:archive_dir] || tardir end
The directory in which remote files are cached
# File lib/autobuild/import/archive.rb, line 147 def cachedir; @options[:cachedir] end
# File lib/autobuild/import/archive.rb, line 70 def extract_tar_on_windows(filename,target) Gem::Package::TarReader.new(Zlib::GzipReader.open(filename)).each do |entry| newname = File.join(target,entry.full_name.slice(entry.full_name.index('/'),entry.full_name.size)) if(entry.directory?) FileUtils.mkdir_p(newname) end if(entry.file?) dir = newname.slice(0,newname.rindex('/')) if(!File.directory?(dir)) FileUtils.mkdir_p(dir) end open(newname, "wb") do |file| file.write(entry.read) end end end end
# File lib/autobuild/import/archive.rb, line 49 def get_url_on_windows(url, filename) uri = URI(url) STDOUT.puts("Host: #{uri.host} Port: #{uri.port} url: #{url}") http = Net::HTTP.new(uri.host,uri.port) http.use_ssl = true if uri.port == 443 http.verify_mode = OpenSSL::SSL::VERIFY_NONE #Unsure, critical?, Review this resp = http.get(uri.request_uri) if resp.code == "301" or resp.code == "302" get_url_on_windows(resp.header['location'],filename) else if(resp.message != 'OK') raise "Could not get File from url \"#{url}\", got response #{resp.message} (#{resp.code})" end open(filename, "wb") do |file| file.write(resp.body) end end end
Returns a string that identifies the remote repository uniquely
This is meant for display purposes
# File lib/autobuild/import/archive.rb, line 159 def repository_id url.dup end
The directory contained in the tar file
DEPRECATED use archive_dir instead
# File lib/autobuild/import/archive.rb, line 151 def tardir; @options[:tardir] end
Updates the downloaded file in cache only if it is needed
# File lib/autobuild/import/archive.rb, line 90 def update_cache(package) do_update = false if !File.file?(cachefile) do_update = true elsif self.update_cached_file? cached_size = File.lstat(cachefile).size cached_mtime = File.lstat(cachefile).mtime size, mtime = nil if @url.scheme == "file" size = File.stat(@url.path).size mtime = File.stat(@url.path).mtime else open @url, :content_length_proc => lambda { |size| } do |file| mtime = file.last_modified end end if mtime && size do_update = (size != cached_size || mtime > cached_mtime) elsif mtime package.warn "%s: archive size is not available for #{@url}, relying on modification time" do_update = (mtime > cached_mtime) elsif size package.warn "%s: archive modification time is not available for #{@url}, relying on size" do_update = (size != cached_size) else package.warn "%s: neither the archive size nor its modification time available for #{@url}, will always update" do_update = true end end if do_update FileUtils.mkdir_p(cachedir) begin if(WINDOWS) get_url_on_windows(@url, "#{cachefile}.partial") else Subprocess.run(package, :import, Autobuild.tool('wget'), '-q', '-P', cachedir, @url, '-O', "#{cachefile}.partial") end rescue Exception FileUtils.rm_f "#{cachefile}.partial" raise end FileUtils.mv "#{cachefile}.partial", cachefile true end end
# File lib/autobuild/import/archive.rb, line 46 def update_cached_file?; @options[:update_cached_file] end