From 3669fe7c3a28aabdcd17e8fcc276b36ca2a0cbad Mon Sep 17 00:00:00 2001 From: mcabrerizo Date: Fri, 7 Oct 2016 18:35:37 +0200 Subject: [PATCH 1/3] B #4687: Uploading gzip files with no tar in vcenter DS should fail gracefully --- src/datastore_mad/remotes/vcenter/cp | 33 ++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/datastore_mad/remotes/vcenter/cp b/src/datastore_mad/remotes/vcenter/cp index 99975a84f1..cae36551ce 100755 --- a/src/datastore_mad/remotes/vcenter/cp +++ b/src/datastore_mad/remotes/vcenter/cp @@ -41,6 +41,12 @@ def is_remote?(file) file.match(%r{^https?://}) end +def is_vmdk?(file) + type = %x{file #{file}} + + type.include? "VMware" +end + def get_type(file) type = %x{file -b --mime-type #{file}} if $?.exitstatus != 0 @@ -111,7 +117,7 @@ def vmdk_info(file) return { :type => :standalone, :file => file_path, - :dir => File.dirname(file_path) + :dir => File.dirname(file_path), } when "application/x-iso9660-image" return { @@ -205,6 +211,7 @@ if is_remote?(file_path) || needs_unpack?(file_path) end delete_file = true + original_path = File.basename(file_path) file_path = temp_file end @@ -220,7 +227,29 @@ when :flat end files_to_upload.each_with_index do |f, index| - path = "#{target_path}/#{File.basename(f)}" + path = "#{target_path}/#{File.basename(f)}" + + # Change path for gzipped standalone file + if(target_path == File.basename(f)) + path = "#{target_path}/#{original_path}" + + # remove gz or bz2 if part of filename + if path.end_with?("gz") and is_vmdk?(f) + path.gsub!(/gz$/,'') + end + + if path.end_with?("bz2") and is_vmdk?(f) + path.gsub!(/bz2$/,'') + end + end + + # Change path if vmdk is part of filename + # but it's not the extension' + if /[^.]+vmdk$/.match(path) and is_vmdk?(f) + path.gsub!(/vmdk$/,'') + extension = '.vmdk' + end + if index == files_to_upload.size - 1 uploader_args = hostname + " " + ds_name + " " + "#{path}#{extension}" + " " + f From b58ae679c70c7b52ca35a98e06a51ed7d3e47643 Mon Sep 17 00:00:00 2001 From: mcabrerizo Date: Fri, 7 Oct 2016 18:39:57 +0200 Subject: [PATCH 2/3] B #4687: Uploading gzip files with no tar in vcenter DS should fail gracefully --- src/datastore_mad/remotes/vcenter/cp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datastore_mad/remotes/vcenter/cp b/src/datastore_mad/remotes/vcenter/cp index cae36551ce..bad912f993 100755 --- a/src/datastore_mad/remotes/vcenter/cp +++ b/src/datastore_mad/remotes/vcenter/cp @@ -117,7 +117,7 @@ def vmdk_info(file) return { :type => :standalone, :file => file_path, - :dir => File.dirname(file_path), + :dir => File.dirname(file_path) } when "application/x-iso9660-image" return { From a09c4f08f2738c88335af089e5657695b215b52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tino=20V=C3=A1zquez?= Date: Fri, 7 Oct 2016 19:04:33 +0200 Subject: [PATCH 3/3] Update cp --- src/datastore_mad/remotes/vcenter/cp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datastore_mad/remotes/vcenter/cp b/src/datastore_mad/remotes/vcenter/cp index bad912f993..faae47d14c 100755 --- a/src/datastore_mad/remotes/vcenter/cp +++ b/src/datastore_mad/remotes/vcenter/cp @@ -117,7 +117,7 @@ def vmdk_info(file) return { :type => :standalone, :file => file_path, - :dir => File.dirname(file_path) + :dir => File.dirname(file_path) } when "application/x-iso9660-image" return {