Module: Uricp::Strategy::Common

Constant Summary collapse

PIPE_URI =
URI('pipe:/')

Instance Attribute Summary collapse

Attributes included from CurlPrimitives

#options

Instance Method Summary collapse

Methods included from CurlPrimitives

#authentication, #curl_command, #curl_download_to_pipe, #curl_manifest, #curl_upload_from, #from, #from=, #http_authentication?, #to, #to=

Instance Attribute Details

#proposed_optionsObject (readonly)

Returns the value of attribute proposed_options.



13
14
15
# File 'lib/uricp/strategy/common.rb', line 13

def proposed_options
  @proposed_options
end

Instance Method Details

#all_local_files?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/uricp/strategy/common.rb', line 22

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

#always_write_sparse?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/uricp/strategy/common.rb', line 38

def always_write_sparse?
  options['force']
end

#compression_required?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/uricp/strategy/common.rb', line 26

def compression_required?
  options['compress']
end

#conversion_required?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/uricp/strategy/common.rb', line 34

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

#encoding(io) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/uricp/strategy/common.rb', line 50

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

#file_source?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/uricp/strategy/common.rb', line 84

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

#format_change?Boolean

Returns:

  • (Boolean)


70
71
72
73
74
# File 'lib/uricp/strategy/common.rb', line 70

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

#get_temp_filename(filename) ⇒ Object



94
95
96
# File 'lib/uricp/strategy/common.rb', line 94

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

#initialize(options) ⇒ Object



8
9
10
11
# File 'lib/uricp/strategy/common.rb', line 8

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

#lz4?(magic) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/uricp/strategy/common.rb', line 42

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

#lz4_source?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/uricp/strategy/common.rb', line 76

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

#proposed_pathObject



98
99
100
# File 'lib/uricp/strategy/common.rb', line 98

def proposed_path
  proposed_options['from_uri'].path
end

#qcow2?(magic) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/uricp/strategy/common.rb', line 46

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

#raw_target?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/uricp/strategy/common.rb', line 80

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

#segmented?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/uricp/strategy/common.rb', line 30

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

#sequence_complete?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/uricp/strategy/common.rb', line 88

def sequence_complete?
  from == to
end

#supported_source?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/uricp/strategy/common.rb', line 106

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

#temp_uriObject



102
103
104
# File 'lib/uricp/strategy/common.rb', line 102

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

#unsupported_transferObject Also known as: command



15
16
17
18
# File 'lib/uricp/strategy/common.rb', line 15

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