|
26 | 26 | import java.io.FileOutputStream; |
27 | 27 | import java.io.IOException; |
28 | 28 | import java.nio.file.Files; |
| 29 | +import java.nio.file.Path; |
29 | 30 | import java.nio.file.Paths; |
30 | 31 | import java.text.DateFormat; |
31 | 32 | import java.text.SimpleDateFormat; |
|
65 | 66 | import org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer; |
66 | 67 | import org.apache.cloudstack.storage.command.SnapshotAndCopyCommand; |
67 | 68 | import org.apache.cloudstack.storage.command.SyncVolumePathCommand; |
| 69 | +import org.apache.cloudstack.storage.formatinspector.Qcow2Inspector; |
68 | 70 | import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; |
69 | 71 | import org.apache.cloudstack.storage.to.SnapshotObjectTO; |
70 | 72 | import org.apache.cloudstack.storage.to.TemplateObjectTO; |
@@ -2637,6 +2639,22 @@ public Answer handleDownloadTemplateToPrimaryStorage(DirectDownloadCommand cmd) |
2637 | 2639 |
|
2638 | 2640 | template = storagePoolMgr.createPhysicalDiskFromDirectDownloadTemplate(tempFilePath, destTemplatePath, destPool, cmd.getFormat(), cmd.getWaitInMillSeconds()); |
2639 | 2641 |
|
| 2642 | + String templatePath = template.getPath(); |
| 2643 | + if (templatePath != null) { |
| 2644 | + try { |
| 2645 | + Qcow2Inspector.validateQcow2File(templatePath); |
| 2646 | + } catch (RuntimeException e) { |
| 2647 | + try { |
| 2648 | + Files.deleteIfExists(Path.of(templatePath)); |
| 2649 | + } catch (IOException ioException) { |
| 2650 | + s_logger.warn(String.format("Unable to remove file [%s]; consider removing it manually.", templatePath), ioException); |
| 2651 | + } |
| 2652 | + |
| 2653 | + s_logger.error(String.format("The downloaded file [%s] is not a valid QCOW2.", templatePath), e); |
| 2654 | + return new DirectDownloadAnswer(false, "The downloaded file is not a valid QCOW2. Ask the administrator to check the logs for more details.", true); |
| 2655 | + } |
| 2656 | + } |
| 2657 | + |
2640 | 2658 | if (!storagePoolMgr.disconnectPhysicalDisk(pool.getPoolType(), pool.getUuid(), destTemplatePath)) { |
2641 | 2659 | logger.warn("Unable to disconnect physical disk at path: " + destTemplatePath + ", in storage pool id: " + pool.getUuid()); |
2642 | 2660 | } |
|
0 commit comments