class FPM::Fry::Source::Archive
Used to build from an archive.
@example in a recipe
source 'http://curl.haxx.se/download/curl-7.36.0.tar.gz', checksum: '33015795d5650a2bfdd9a4a28ce4317cef944722a5cfca0d1563db8479840e90'
It is highly advised to supply a checksum ( althought it’s not mandatory ). This checksum will be used to test for cache validity and data integrity. The checksum algorithm is automatically guessed based on the length of the checksum.
- 40 characters = sha1 - 64 characters = sha256 - 128 characters = sha512
Let’s be honest: all other checksum algorithms aren’t or shouldn’t be in use anyway.
Constants
- CACHE_CLASSES
- REGEX
Attributes
Public Class Methods
# File lib/fpm/fry/source/archive.rb, line 36 def self.aliases [:package,:http] end
Guesses if the given url is an archive.
@example not an archive
FPM::Fry::Source::Archive.guess("bzr://something") # => nil
@example an archive
FPM::Fry::Source::Archive.guess("https://some/thing.tar.gz") #=> 6
@return [nil] when it’s not an archive @return [Numeric] number of characters used
# File lib/fpm/fry/source/archive.rb, line 50 def self.guess( url ) Source::guess_regex(REGEX, url) end
@return [:archive]
# File lib/fpm/fry/source/archive.rb, line 32 def self.name :package end
@param [URI] url @param [Hash] options @option options [Cabin::Channel] :logger (default cabin channel) @option options [String] :checksum a checksum of the archive @raise [UnknownArchiveType] when the archive type is unknown
# File lib/fpm/fry/source/archive.rb, line 283 def initialize( url, options = {} ) @url = URI(url) @cache_class = guess_cache_class(@url) @logger = options.fetch(:logger){ Cabin::Channel.get } @checksum = options[:checksum] @checksum_algorithm = guess_checksum_algorithm(options[:checksum]) @file_map = options[:file_map] @to = options[:to] end
Public Instance Methods
Creates a cache.
@param [String] tempdir @return [TarCache] for plain .tar files @return [TarGzCache] for .tar.gz files @return [TarBz2Cache] for .tar.bz2 files @return [ZipCache] for .zip files @return [PlainCache] for .bin files
# File lib/fpm/fry/source/archive.rb, line 301 def build_cache(tempdir) @cache_class.new(self, tempdir) end
Private Instance Methods
# File lib/fpm/fry/source/archive.rb, line 306 def guess_cache_class( url ) CACHE_CLASSES.each do |ext,klass| if url.path.end_with?(ext) return klass end end raise UnknownArchiveType.new("Unknown archive type", url: url.to_s, known_extensions: CACHE_CLASSES.keys) end
# File lib/fpm/fry/source/archive.rb, line 315 def guess_checksum_algorithm( checksum ) case(checksum) when nil return Digest::SHA256 when /\A(sha512:)?[0-9a-f]{128}\z/ then return Digest::SHA512 when /\A(sha256:)?[0-9a-f]{64}\z/ then return Digest::SHA256 when /\A(sha1:)?[0-9a-f]{40}\z/ then return Digest::SHA1 else raise "Unknown checksum algorithm" end end