Module: Uricp::Strategy::Common
- Includes:
- Methadone::CLILogging, CurlPrimitives
- Included in:
- CachedGet, Cleaner, LocalConvert, LocalLink, PipedCache, PipedCacheConvert, PipedCompress, PipedDecompress, PipedLocalCompress, PipedLocalDecompress, PipedLocalGet, PipedLocalPut, PipedRemoteGet, RemotePut, SegmentedRemotePut, Sweeper
- Defined in:
- lib/uricp/strategy/common.rb
Constant Summary
collapse
- PIPE_URI =
URI('pipe:/')
Instance Attribute Summary collapse
#options
Instance Method Summary
collapse
#authentication, #curl_command, #curl_download_to_pipe, #curl_manifest, #curl_upload_from, #from, #from=, #http_authentication?, #to, #to=
Instance Attribute Details
#proposed_options ⇒ Object
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
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
38
39
40
|
# File 'lib/uricp/strategy/common.rb', line 38
def always_write_sparse?
options['force']
end
|
#compression_required? ⇒ Boolean
26
27
28
|
# File 'lib/uricp/strategy/common.rb', line 26
def compression_required?
options['compress']
end
|
#conversion_required? ⇒ 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
84
85
86
|
# File 'lib/uricp/strategy/common.rb', line 84
def file_source?
from.scheme == 'file'
end
|
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
42
43
44
|
# File 'lib/uricp/strategy/common.rb', line 42
def lz4?(magic)
magic.unpack('V') == [0x184D2204]
end
|
#lz4_source? ⇒ Boolean
76
77
78
|
# File 'lib/uricp/strategy/common.rb', line 76
def lz4_source?
options['source-format'] == :lz4
end
|
#proposed_path ⇒ Object
98
99
100
|
# File 'lib/uricp/strategy/common.rb', line 98
def proposed_path
proposed_options['from_uri'].path
end
|
#qcow2?(magic) ⇒ Boolean
46
47
48
|
# File 'lib/uricp/strategy/common.rb', line 46
def qcow2?(magic)
magic.unpack('a3C') == ['QFI',0xfb]
end
|
#raw_target? ⇒ Boolean
80
81
82
|
# File 'lib/uricp/strategy/common.rb', line 80
def raw_target?
options['target-format'] == :raw
end
|
#segmented? ⇒ Boolean
30
31
32
|
# File 'lib/uricp/strategy/common.rb', line 30
def segmented?
options['segment-size']
end
|
#sequence_complete? ⇒ Boolean
88
89
90
|
# File 'lib/uricp/strategy/common.rb', line 88
def sequence_complete?
from == to
end
|
#supported_source? ⇒ Boolean
106
107
108
|
# File 'lib/uricp/strategy/common.rb', line 106
def supported_source?
options['source-format'] && !lz4_source?
end
|
#temp_uri ⇒ Object
102
103
104
|
# File 'lib/uricp/strategy/common.rb', line 102
def temp_uri
URI.join('file:///', get_temp_filename(options['temp']))
end
|
#unsupported_transfer ⇒ Object
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
|