Skip to content

Commit 4284ac3

Browse files
committed
fix(server): prevent boolean overwrite in template cleanup during account removal (#13612)
1 parent 0e43c6a commit 4284ac3

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

server/src/main/java/com/cloud/user/AccountManagerImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,15 +1016,20 @@ protected boolean cleanupAccount(AccountVO account, long callerUserId, Account c
10161016
logger.debug("Successfully deleted snapshots directories for all volumes under account {} across all zones", account);
10171017
}
10181018

1019+
10191020
// clean up templates
10201021
List<VMTemplateVO> userTemplates = _templateDao.listByAccountId(accountId);
10211022
boolean allTemplatesDeleted = true;
10221023
for (VMTemplateVO template : userTemplates) {
10231024
if (template.getRemoved() == null) {
10241025
try {
1025-
allTemplatesDeleted = _tmpltMgr.delete(callerUserId, template.getId(), null);
1026+
// Fix 1: Prevent boolean overwriting by checking failure explicitly
1027+
if (!_tmpltMgr.delete(callerUserId, template.getId(), null)) {
1028+
logger.warn("TemplateManager returned false when deleting template {} for account {}", template, account);
1029+
allTemplatesDeleted = false;
1030+
}
10261031
} catch (Exception e) {
1027-
logger.warn("Failed to delete template {} while removing account {} due to: ", template, account, e);
1032+
logger.warn("Failed to delete template {} while removing account {} due to exception: ", template, account, e);
10281033
allTemplatesDeleted = false;
10291034
}
10301035
}

0 commit comments

Comments
 (0)