Skip to content

Commit 8c4a085

Browse files
Validate the direct downloaded template file format (QCOW2) if the template file exists (#10332)
* Validate the direct downloaded template file format (QCOW2) if the template file exists * string format not required
1 parent 59e0543 commit 8c4a085

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,8 +2472,15 @@ public Answer handleDownloadTemplateToPrimaryStorage(DirectDownloadCommand cmd)
24722472

24732473
template = storagePoolMgr.createPhysicalDiskFromDirectDownloadTemplate(tempFilePath, destTemplatePath, destPool, cmd.getFormat(), cmd.getWaitInMillSeconds());
24742474

2475-
String templatePath = template.getPath();
2476-
if (templatePath != null) {
2475+
String templatePath = null;
2476+
if (template != null) {
2477+
templatePath = template.getPath();
2478+
}
2479+
if (StringUtils.isEmpty(templatePath)) {
2480+
logger.warn("Skipped validation whether downloaded file is QCOW2 for template {}, due to downloaded template path is empty", template.getName());
2481+
} else if (!new File(templatePath).exists()) {
2482+
logger.warn("Skipped validation whether downloaded file is QCOW2 for template {}, due to downloaded template path is not valid: {}", template.getName(), templatePath);
2483+
} else {
24772484
try {
24782485
Qcow2Inspector.validateQcow2File(templatePath);
24792486
} catch (RuntimeException e) {

0 commit comments

Comments
 (0)