From 182a4cf2e91468c3d32f4709ae79dc573fa5e4ed Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Mon, 23 Apr 2012 19:00:46 -0700 Subject: [PATCH] CS-14555: Calculated checksum before unzip Otherwise checksum would be overrided by wrong value. --- .../cloud/storage/template/DownloadManagerImpl.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/com/cloud/storage/template/DownloadManagerImpl.java b/core/src/com/cloud/storage/template/DownloadManagerImpl.java index 156dd0b25a5..07b93456eb4 100755 --- a/core/src/com/cloud/storage/template/DownloadManagerImpl.java +++ b/core/src/com/cloud/storage/template/DownloadManagerImpl.java @@ -317,6 +317,13 @@ public class DownloadManagerImpl implements DownloadManager { String finalTemplatePath = _templateDir + File.separator + dnld.getAccountId() + File.separator + dnld.getId() + File.separator; dnld.setTmpltPath(finalTemplatePath); + File originalTemplate = new File(td.getDownloadLocalPath()); + String checkSum = computeCheckSum(originalTemplate); + if (checkSum == null) { + s_logger.warn("Something wrong happened when try to calculate the checksum of downloaded template!"); + } + dnld.setCheckSum(checkSum); + int imgSizeGigs = (int) Math.ceil(_storage.getSize(td.getDownloadLocalPath()) * 1.0d / (1024 * 1024 * 1024)); imgSizeGigs++; // add one just in case long timeout = imgSizeGigs * installTimeoutPerGig; @@ -393,9 +400,6 @@ public class DownloadManagerImpl implements DownloadManager { } } - String checkSum = computeCheckSum(downloadedTemplate); - dnld.setCheckSum(checkSum); - if (!loc.save()) { s_logger.warn("Cleaning up because we're unable to save the formats"); loc.purge();