Skip to content
Open
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
9 changes: 7 additions & 2 deletions server/src/main/java/com/cloud/user/AccountManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1016,15 +1016,20 @@ protected boolean cleanupAccount(AccountVO account, long callerUserId, Account c
logger.debug("Successfully deleted snapshots directories for all volumes under account {} across all zones", account);
}


// clean up templates
List<VMTemplateVO> userTemplates = _templateDao.listByAccountId(accountId);
boolean allTemplatesDeleted = true;
for (VMTemplateVO template : userTemplates) {
if (template.getRemoved() == null) {
try {
allTemplatesDeleted = _tmpltMgr.delete(callerUserId, template.getId(), null);
// Fix 1: Prevent boolean overwriting by checking failure explicitly
if (!_tmpltMgr.delete(callerUserId, template.getId(), null)) {
logger.warn("TemplateManager returned false when deleting template {} for account {}", template, account);
allTemplatesDeleted = false;
}
} catch (Exception e) {
logger.warn("Failed to delete template {} while removing account {} due to: ", template, account, e);
logger.warn("Failed to delete template {} while removing account {} due to exception: ", template, account, e);
allTemplatesDeleted = false;
}
}
Expand Down