uricp 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,6 @@ require 'uricp/version'
2
2
  require 'uricp/curl_primitives'
3
3
  require 'uricp/strategy/common'
4
4
  require 'uricp/strategy/cache_common'
5
- require 'uricp/strategy/local_convert_common'
6
5
  require 'uricp/strategy/local_convert'
7
6
  require 'uricp/strategy/local_link'
8
7
  require 'uricp/strategy/piped_cache'
@@ -25,6 +24,7 @@ module Uricp
25
24
 
26
25
  UnsupportedURLtype = Class.new(ArgumentError)
27
26
  MissingCache = Class.new(ArgumentError)
27
+ UnsupportedConversion = Class.new(ArgumentError)
28
28
 
29
29
  end
30
30
 
@@ -2,11 +2,16 @@ module Uricp::Strategy
2
2
 
3
3
  class LocalConvert
4
4
 
5
- include Uricp::Strategy::LocalConvertCommon
5
+ include Uricp::Strategy::Common
6
6
 
7
7
  def appropriate?
8
8
  if conversion_required? && file_source? && supported_source?
9
- return proposal
9
+ if new_qemu? || supported_conversion?
10
+ return proposal
11
+ else
12
+ raise Uricp::UnsupportedConversion,
13
+ "qemu-img does not support required conversion"
14
+ end
10
15
  end
11
16
  debug "#{self.class.name}: not appropriate"
12
17
  false
@@ -30,6 +35,37 @@ module Uricp::Strategy
30
35
  self
31
36
  end
32
37
 
38
+ def new_qemu?
39
+ @new_qemu ||= !!(`qemu-img convert -O qcow2 -o ? a b` =~ /^compat/m)
40
+ end
41
+
42
+ def supported_conversion?
43
+ ([:qcow3, :qcow2v3] & [options['source-format'], options['target-format']]).empty?
44
+ end
45
+
46
+ def qemu_img_command(target)
47
+ "qemu-img convert #{conversion_options} #{from.path} #{target};"
48
+ end
49
+
50
+ def conversion_options
51
+ case options['target-format']
52
+ when :raw
53
+ '-O raw'
54
+ when :qcow2
55
+ "#{compress_option} -O qcow2 #{compat_option}"
56
+ when :qcow3, :qcow2v3
57
+ "#{compress_option} -O qcow2 -o compat=1.1"
58
+ end
59
+ end
60
+
61
+ def compat_option
62
+ "-o compat=0.10" if new_qemu?
63
+ end
64
+
65
+ def compress_option
66
+ options['compress'] && '-c'
67
+ end
68
+
33
69
  end
34
70
 
35
71
  end
@@ -1,4 +1,4 @@
1
1
  module Uricp
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  DEFAULT_SEGMENT_SIZE = "5 GiB"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uricp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -224,7 +224,6 @@ files:
224
224
  - lib/uricp/strategy/cleaner.rb
225
225
  - lib/uricp/strategy/common.rb
226
226
  - lib/uricp/strategy/local_convert.rb
227
- - lib/uricp/strategy/local_convert_common.rb
228
227
  - lib/uricp/strategy/local_link.rb
229
228
  - lib/uricp/strategy/piped_cache.rb
230
229
  - lib/uricp/strategy/piped_cache_convert.rb
@@ -1,29 +0,0 @@
1
- module Uricp::Strategy
2
-
3
- module LocalConvertCommon
4
-
5
- include Uricp::Strategy::Common
6
-
7
- def qemu_img_command(target)
8
- "qemu-img convert #{conversion_options} #{from.path} #{target};"
9
- end
10
-
11
- def conversion_options
12
- case options['target-format']
13
- when :raw
14
- '-O raw'
15
- when :qcow2
16
- "#{compress_option} -O qcow2 -o compat=0.10"
17
- when :qcow3, :qcow2v3
18
- "#{compress_option} -O qcow2 -o compat=1.1"
19
- end
20
- end
21
-
22
- def compress_option
23
- options['compress'] && '-c'
24
- end
25
-
26
- end
27
-
28
- end
29
-