Sha256: a4667c226b96409cf19e937fdff3a141d6dffdfb025585f6e8ad29530866175a

Contents?: true

Size: 1.89 KB

Versions: 8

Compression:

Stored size: 1.89 KB

Contents

module Uricp::Strategy
 
  module Common
    
    include Methadone::CLILogging
    include Uricp::CurlPrimitives

    def initialize(options)
      @options = options
      debug "#{self.class.name}: options are #{options.inspect}"
    end

    attr_reader :proposed_options

    def unsupported_transfer
      raise Uricp::UnsupportedURLtype,
        "Unsupported transfer from #{from.to_s} to #{to.to_s}"
    end

    alias :command :unsupported_transfer

    def all_local_files?
      !sequence_complete? && file_source? && to.scheme == 'file'
    end

    def compression_required?
      options['compress']
    end

    def segmented?
      options['segment-size']
    end

    def conversion_required?
      options['target-format']
    end

    def lz4?(magic)
      magic.unpack('V') == [0x184D2204]
    end

    def qcow2?(magic)
      magic.unpack('a3C') == ['QFI',0xfb]
    end

    def encoding(io)
      magic = io.read(4).to_s
      case
      when lz4?(magic)
        :lz4
      when qcow2?(magic)
        version = io.read(4)
	case version.unpack('N')
	when [2]
	  :qcow2
	when [3]
	  :qcow3
	else
	  :qcow2un
	end
      else
        :raw
      end
    end

    def format_change?
      conversion_required? && (
        options['source-format'] != options['target-format']
      )
    end

    def lz4_source?
      options['source-format'] == :lz4
    end

    def raw_target?
      options['target-format'] == :raw
    end

    def file_source?
      from.scheme == 'file'
    end

    def sequence_complete?
      from == to
    end

    PIPE_URI = URI('pipe:/')

    def get_temp_filename(filename)
      Dir::Tmpname.make_tmpname(filename, nil)
    end

    def proposed_path
      proposed_options['from_uri'].path
    end

    def temp_uri
      URI.join('file:///', get_temp_filename(options['temp']))
    end

    def supported_source?
      options['source-format'] && !lz4_source?
    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
uricp-0.0.9 lib/uricp/strategy/common.rb
uricp-0.0.8 lib/uricp/strategy/common.rb
uricp-0.0.7 lib/uricp/strategy/common.rb
uricp-0.0.6 lib/uricp/strategy/common.rb
uricp-0.0.5 lib/uricp/strategy/common.rb
uricp-0.0.4 lib/uricp/strategy/common.rb
uricp-0.0.3 lib/uricp/strategy/common.rb
uricp-0.0.2 lib/uricp/strategy/common.rb