|
88 | 88 | import org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer; |
89 | 89 | import org.apache.cloudstack.storage.command.SnapshotAndCopyCommand; |
90 | 90 | import org.apache.cloudstack.storage.command.SyncVolumePathCommand; |
| 91 | +import org.apache.cloudstack.storage.formatinspector.Qcow2Inspector; |
91 | 92 | import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; |
92 | 93 | import org.apache.cloudstack.storage.to.SnapshotObjectTO; |
93 | 94 | import org.apache.cloudstack.storage.to.TemplateObjectTO; |
|
119 | 120 | import java.io.FileOutputStream; |
120 | 121 | import java.io.IOException; |
121 | 122 | import java.nio.file.Files; |
| 123 | +import java.nio.file.Path; |
122 | 124 | import java.nio.file.Paths; |
123 | 125 | import java.text.DateFormat; |
124 | 126 | import java.text.SimpleDateFormat; |
@@ -2440,6 +2442,22 @@ public Answer handleDownloadTemplateToPrimaryStorage(DirectDownloadCommand cmd) |
2440 | 2442 |
|
2441 | 2443 | template = storagePoolMgr.createPhysicalDiskFromDirectDownloadTemplate(tempFilePath, destTemplatePath, destPool, cmd.getFormat(), cmd.getWaitInMillSeconds()); |
2442 | 2444 |
|
| 2445 | + String templatePath = template.getPath(); |
| 2446 | + if (templatePath != null) { |
| 2447 | + try { |
| 2448 | + Qcow2Inspector.validateQcow2File(templatePath); |
| 2449 | + } catch (RuntimeException e) { |
| 2450 | + try { |
| 2451 | + Files.deleteIfExists(Path.of(templatePath)); |
| 2452 | + } catch (IOException ioException) { |
| 2453 | + s_logger.warn(String.format("Unable to remove file [%s]; consider removing it manually.", templatePath), ioException); |
| 2454 | + } |
| 2455 | + |
| 2456 | + s_logger.error(String.format("The downloaded file [%s] is not a valid QCOW2.", templatePath), e); |
| 2457 | + return new DirectDownloadAnswer(false, "The downloaded file is not a valid QCOW2. Ask the administrator to check the logs for more details.", true); |
| 2458 | + } |
| 2459 | + } |
| 2460 | + |
2443 | 2461 | if (!storagePoolMgr.disconnectPhysicalDisk(pool.getPoolType(), pool.getUuid(), destTemplatePath)) { |
2444 | 2462 | s_logger.warn("Unable to disconnect physical disk at path: " + destTemplatePath + ", in storage pool id: " + pool.getUuid()); |
2445 | 2463 | } |
|
0 commit comments