Sha256: b53cc475cfe2255456abc4285bede26ab057033476dfb88d402781347beeabf5
Contents?: true
Size: 1.7 KB
Versions: 12
Compression:
Stored size: 1.7 KB
Contents
# frozen_string_literal: true module Uricp::Strategy class LocalConvert include Uricp::Strategy::Common def appropriate? if conversion_required? && file_source? && supported_source? return proposal if new_qemu? || supported_conversion? raise Uricp::UnsupportedConversion, 'qemu-img does not support required conversion' end debug "#{self.class.name}: not appropriate" false end def command qemu_img_command(proposed_path) end def proposal @proposed_options = options.dup if to.scheme == 'file' @proposed_options['from_uri'] = @proposed_options['to_uri'] else @proposed_options['from_uri'] = temp_uri @proposed_options['clean'] ||= [] @proposed_options['clean'] << proposed_path end @proposed_options.delete('source-format') @proposed_options.delete('target-format') self end def new_qemu? @new_qemu ||= !!(`qemu-img convert -O qcow2 -o ? a b` =~ /\bcompat\b/m) end def supported_conversion? ([:qcow3, :qcow2v3] & [options['source-format'], options['target-format']]).empty? # rubocop:disable Style/SymbolArray end def qemu_img_command(target) "qemu-img convert #{conversion_options} #{from.path} #{target};" end def conversion_options case options['target-format'] when :raw '-O raw' when :qcow2 "#{compress_option} -O qcow2 #{compat_option}" when :qcow3, :qcow2v3 "#{compress_option} -O qcow2 -o compat=1.1" end end def compat_option '-o compat=0.10' if new_qemu? end def compress_option options['compress'] && '-c' end end end
Version data entries
12 entries across 12 versions & 1 rubygems