cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] DaanHoogland commented on a change in pull request #2405: CLOUDSTACK-10146 checksum in java instead of script
Date Thu, 01 Jan 1970 00:00:00 GMT
DaanHoogland commented on a change in pull request #2405: CLOUDSTACK-10146 checksum in java
instead of script
URL: https://github.com/apache/cloudstack/pull/2405#discussion_r161609584
 
 

 ##########
 File path: agent/src/com/cloud/agent/direct/download/DirectTemplateDownloaderImpl.java
 ##########
 @@ -149,36 +154,16 @@ public DirectTemplateInformation getTemplateInformation() {
         return new DirectTemplateInformation(installPath, size, checksum);
     }
 
-    /**
-     * Return checksum command from algorithm
-     */
-    private String getChecksumCommandFromAlgorithm(String algorithm) {
-        if (algorithm.equalsIgnoreCase("MD5")) {
-            return "md5sum";
-        } else if (algorithm.equalsIgnoreCase("SHA-1")) {
-            return "sha1sum";
-        } else if (algorithm.equalsIgnoreCase("SHA-224")) {
-            return "sha224sum";
-        } else if (algorithm.equalsIgnoreCase("SHA-256")) {
-            return "sha256sum";
-        } else if (algorithm.equalsIgnoreCase("SHA-384")) {
-            return "sha384sum";
-        } else if (algorithm.equalsIgnoreCase("SHA-512")) {
-            return "sha512sum";
-        } else {
-            throw new CloudRuntimeException("Unknown checksum algorithm: " + algorithm);
-        }
-    }
-
     @Override
     public boolean validateChecksum() {
         if (StringUtils.isNotBlank(checksum)) {
-            ChecksumValue providedChecksum = new ChecksumValue(checksum);
-            String algorithm = providedChecksum.getAlgorithm();
-            String checksumCommand = "echo '%s %s' | %s -c --quiet";
-            String cmd = String.format(checksumCommand, providedChecksum.getChecksum(), downloadedFilePath,
getChecksumCommandFromAlgorithm(algorithm));
-            int result = Script.runSimpleBashScriptForExitValue(cmd);
-            return result == 0;
+            try {
+                return DigestHelper.check(checksum, new FileInputStream(downloadedFilePath));
+            } catch (IOException e) {
+                throw new CloudRuntimeException("could not check sum for file: " + downloadedFilePath);
 
 Review comment:
   yes, I agree. though people have been pushing towards not including root causes in exception
traces i will add it!

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message