|
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;
|
|
63 | 64 | import org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer;
|
64 | 65 | import org.apache.cloudstack.storage.command.SnapshotAndCopyCommand;
|
65 | 66 | import org.apache.cloudstack.storage.command.SyncVolumePathCommand;
|
| 67 | +import org.apache.cloudstack.storage.formatinspector.Qcow2Inspector; |
66 | 68 | import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
67 | 69 | import org.apache.cloudstack.storage.to.SnapshotObjectTO;
|
68 | 70 | import org.apache.cloudstack.storage.to.TemplateObjectTO;
|
@@ -2394,6 +2396,22 @@ public Answer handleDownloadTemplateToPrimaryStorage(DirectDownloadCommand cmd)
|
2394 | 2396 |
|
2395 | 2397 | template = storagePoolMgr.createPhysicalDiskFromDirectDownloadTemplate(tempFilePath, destTemplatePath, destPool, cmd.getFormat(), cmd.getWaitInMillSeconds());
|
2396 | 2398 |
|
| 2399 | + String templatePath = template.getPath(); |
| 2400 | + if (templatePath != null) { |
| 2401 | + try { |
| 2402 | + Qcow2Inspector.validateQcow2File(templatePath); |
| 2403 | + } catch (RuntimeException e) { |
| 2404 | + try { |
| 2405 | + Files.deleteIfExists(Path.of(templatePath)); |
| 2406 | + } catch (IOException ioException) { |
| 2407 | + s_logger.warn(String.format("Unable to remove file [%s]; consider removing it manually.", templatePath), ioException); |
| 2408 | + } |
| 2409 | + |
| 2410 | + s_logger.error(String.format("The downloaded file [%s] is not a valid QCOW2.", templatePath), e); |
| 2411 | + return new DirectDownloadAnswer(false, "The downloaded file is not a valid QCOW2. Ask the administrator to check the logs for more details.", true); |
| 2412 | + } |
| 2413 | + } |
| 2414 | + |
2397 | 2415 | if (!storagePoolMgr.disconnectPhysicalDisk(pool.getPoolType(), pool.getUuid(), destTemplatePath)) {
|
2398 | 2416 | s_logger.warn("Unable to disconnect physical disk at path: " + destTemplatePath + ", in storage pool id: " + pool.getUuid());
|
2399 | 2417 | }
|
|
0 commit comments