[
https://issues.apache.org/jira/browse/CLOUDSTACK-10146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16326567#comment-16326567
]
ASF GitHub Bot commented on CLOUDSTACK-10146:
---------------------------------------------
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_r161610342
##########
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:
come to think of it it does not make as much sense in the
NoSuchAlgorithmException case. Doe you agree @marcaurele ?
----------------------------------------------------------------
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:
[email protected]
> Bypass Secondary Storage for KVM templates
> ------------------------------------------
>
> Key: CLOUDSTACK-10146
> URL: https://issues.apache.org/jira/browse/CLOUDSTACK-10146
> Project: CloudStack
> Issue Type: Bug
> Security Level: Public(Anyone can view this level - this is the
> default.)
> Affects Versions: 4.11.0.0
> Reporter: Nicolas Vazquez
> Assignee: Nicolas Vazquez
> Priority: Major
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)