DaanHoogland commented on code in PR #11786:
URL: https://github.com/apache/cloudstack/pull/11786#discussion_r2420454703
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/MultipathSCSIAdapterBase.java:
##########
@@ -436,6 +437,8 @@ String getExtractCommandForDownloadedFile(String
downloadedTemplateFile, String
return "bunzip2 -c " + downloadedTemplateFile + " > " +
templateFile;
} else if (downloadedTemplateFile.endsWith(".gz")) {
return "gunzip -c " + downloadedTemplateFile + " > " +
templateFile;
+ } else if (downloadedTemplateFile.endsWith(".xz")) {
+ return "xz -d -c " + downloadedTemplateFile + " > " + templateFile;
} else {
throw new CloudRuntimeException("Unable to extract template " +
downloadedTemplateFile);
}
Review Comment:
here as well ; how about extracting an extension once and then switch on the
string? it will replace 5 str.endsWith() calls for one
str.substring(str.lastIndexOf(”.”).
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java:
##########
@@ -193,6 +194,8 @@ public static String
getExtractCommandForDownloadedFile(String downloadedTemplat
return "bunzip2 -c " + downloadedTemplateFile + " > " +
templateUuid;
} else if (downloadedTemplateFile.endsWith(".gz")) {
return "gunzip -c " + downloadedTemplateFile + " > " +
templateUuid;
+ } else if (downloadedTemplateFile.endsWith(".xz")) {
+ return "xz -d -c " + downloadedTemplateFile + " > " + templateUuid;
} else {
throw new CloudRuntimeException("Unable to extract template " +
downloadedTemplateFile);
}
Review Comment:
how about extracting an extension once and then switch on the string? it
will replace 5 `str.endsWith()` calls for one
str.substring(str.lastIndexOf(”.”).
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java:
##########
@@ -623,6 +624,8 @@ private String getExtractCommandForDownloadedFile(String
downloadedTemplateFile,
return "bunzip2 -c " + downloadedTemplateFile + " > " +
templateFile;
} else if (downloadedTemplateFile.endsWith(".gz")) {
return "gunzip -c " + downloadedTemplateFile + " > " +
templateFile;
+ } else if (downloadedTemplateFile.endsWith(".xz")) {
+ return "xz -d -c " + downloadedTemplateFile + " > " + templateFile;
} else {
throw new CloudRuntimeException("Unable to extract template " +
downloadedTemplateFile);
}
Review Comment:
end finally ;)
how about extracting an extension once and then switch on the string? it
will replace 5 str.endsWith() calls for one str.substring(str.lastIndexOf(”.”).
##########
plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java:
##########
@@ -549,6 +550,8 @@ private String getExtractCommandForDownloadedFile(String
downloadedTemplateFile,
return "bunzip2 -c " + downloadedTemplateFile + " > " +
templateFile;
} else if (downloadedTemplateFile.endsWith(".gz")) {
return "gunzip -c " + downloadedTemplateFile + " > " +
templateFile;
+ } else if (downloadedTemplateFile.endsWith(".xz")) {
+ return "xz -d -c " + downloadedTemplateFile + " > " + templateFile;
} else {
throw new CloudRuntimeException("Unable to extract template " +
downloadedTemplateFile);
}
Review Comment:
almost finally
how about extracting an extension once and then switch on the string? it
will replace 5 str.endsWith() calls for one str.substring(str.lastIndexOf(”.”).
and also uniofy all those fragments in a utility.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]