Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ private VMTemplateVO createTemplateObjectInDB(SystemVMTemplateDetails details) {
template.setBits(64);
template.setAccountId(Account.ACCOUNT_ID_SYSTEM);
template.setUrl(details.getUrl());
template.setChecksum(details.getChecksum());
template.setChecksum(DigestHelper.prependAlgorithm(details.getChecksum()));
template.setEnablePassword(false);
template.setDisplayText(details.getName());
template.setFormat(details.getFormat());
Expand Down Expand Up @@ -1008,7 +1008,7 @@ private void updateRegisteredTemplateDetails(Long templateId, MetadataTemplateDe

private void updateTemplateUrlChecksumAndGuestOsId(VMTemplateVO templateVO, MetadataTemplateDetails templateDetails) {
templateVO.setUrl(templateDetails.getUrl());
templateVO.setChecksum(templateDetails.getChecksum());
templateVO.setChecksum(DigestHelper.prependAlgorithm(templateDetails.getChecksum()));
GuestOSVO guestOS = guestOSDao.findOneByDisplayName(templateDetails.getGuestOs());
if (guestOS != null) {
templateVO.setGuestOSId(guestOS.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,18 @@ public static String calculateChecksum(File file) {
throw new CloudRuntimeException(errMsg, e);
}
}

public static String prependAlgorithm(String checksum) {
if (StringUtils.isEmpty(checksum)) {
return checksum;
}
int checksumLength = checksum.length();
for (Map.Entry<String, Integer> entry : paddingLengths.entrySet()) {
if (entry.getValue().equals(checksumLength)) {
String algorithm = entry.getKey();
return String.format("{%s}%s", algorithm, checksum);
}
}
return checksum;
}
}
Loading