Class: FPM::Fry::Source::Archive

Inherits:
Object
  • Object
show all
Defined in:
lib/fpm/fry/source/archive.rb

Overview

Used to build from an archive.

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.

Examples:

in a recipe

source 'http://curl.haxx.se/download/curl-7.36.0.tar.gz',
  checksum: '33015795d5650a2bfdd9a4a28ce4317cef944722a5cfca0d1563db8479840e90'

Defined Under Namespace

Classes: Cache, PlainCache, RedirectError, TarBz2Cache, TarCache, TarGzCache, UnknownArchiveType, ZipCache

Constant Summary collapse

REGEX =
%r!\Ahttps?:!
CACHE_CLASSES =
{
  '.tar' => TarCache,
  '.tar.gz' => TarGzCache,
  '.tgz' => TarGzCache,
  '.tar.bz2' => TarBz2Cache,
  '.zip' => ZipCache,
  '.bin' => PlainCache,
  '.bundle' => PlainCache
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Archive

Returns a new instance of Archive.

Parameters:

  • url (URI)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :logger (Cabin::Channel) — default: default cabin channel
  • :checksum (String)

    a checksum of the archive

Raises:



283
284
285
286
287
288
289
290
291
# 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

Instance Attribute Details

#checksumObject (readonly)

Returns the value of attribute checksum.



276
277
278
# File 'lib/fpm/fry/source/archive.rb', line 276

def checksum
  @checksum
end

#checksum_algorithmObject (readonly)

Returns the value of attribute checksum_algorithm.



276
277
278
# File 'lib/fpm/fry/source/archive.rb', line 276

def checksum_algorithm
  @checksum_algorithm
end

#dataObject (readonly)

Returns the value of attribute data.



276
277
278
# File 'lib/fpm/fry/source/archive.rb', line 276

def data
  @data
end

#file_mapObject (readonly)

Returns the value of attribute file_map.



276
277
278
# File 'lib/fpm/fry/source/archive.rb', line 276

def file_map
  @file_map
end

#loggerObject (readonly)

Returns the value of attribute logger.



276
277
278
# File 'lib/fpm/fry/source/archive.rb', line 276

def logger
  @logger
end

#toObject (readonly)

Returns the value of attribute to.



276
277
278
# File 'lib/fpm/fry/source/archive.rb', line 276

def to
  @to
end

#urlObject (readonly)

Returns the value of attribute url.



276
277
278
# File 'lib/fpm/fry/source/archive.rb', line 276

def url
  @url
end

Class Method Details

.aliasesObject



36
37
38
# File 'lib/fpm/fry/source/archive.rb', line 36

def self.aliases
  [:package,:http]
end

.guess(url) ⇒ nil, Numeric

Guesses if the given url is an archive.

Examples:

not an archive

FPM::Fry::Source::Archive.guess("bzr://something") # => nil

an archive

FPM::Fry::Source::Archive.guess("https://some/thing.tar.gz") #=> 6

Returns:

  • (nil)

    when it’s not an archive

  • (Numeric)

    number of characters used



50
51
52
# File 'lib/fpm/fry/source/archive.rb', line 50

def self.guess( url )
  Source::guess_regex(REGEX, url)
end

.name:archive

Returns:

  • (:archive)


32
33
34
# File 'lib/fpm/fry/source/archive.rb', line 32

def self.name
  :package
end

Instance Method Details

#build_cache(tempdir) ⇒ TarCache, ...

Creates a cache.

Parameters:

  • tempdir (String)

Returns:



301
302
303
# File 'lib/fpm/fry/source/archive.rb', line 301

def build_cache(tempdir)
  @cache_class.new(self, tempdir)
end