diff --git a/src/main/java/com/drunkendev/confluence/plugins/attachments/PurgeAttachmentsJob.java b/src/main/java/com/drunkendev/confluence/plugins/attachments/PurgeAttachmentsJob.java index dca6996..8fd46a6 100644 --- a/src/main/java/com/drunkendev/confluence/plugins/attachments/PurgeAttachmentsJob.java +++ b/src/main/java/com/drunkendev/confluence/plugins/attachments/PurgeAttachmentsJob.java @@ -245,20 +245,15 @@ private int filterAge(List prior, int maxDaysOld) { } private int filterSize(List prior, long maxTotalSize) { - long fileSize = 0; long maxSizeKiB = maxTotalSize * 1024 * 1024; - - int m = -1; - - for (int i = 0; i < prior.size(); i++) { - fileSize += prior.get(i).getFileSize(); - if (fileSize > maxSizeKiB) { - m = i; - } else if (m > -1) { - break; + long total = 0; + for (int i = prior.size() - 1; i >= 0; i--) { + total += prior.get(i).getFileSize(); + if (total > maxSizeKiB) { + return i; } } - return m; + return -1; } private void mailResultsPlain(Map> mailEntries1) throws MailException { @@ -360,7 +355,7 @@ public int compare(MailLogEntry o1, MailLogEntry o2) { sb.append("

Started: ") .append(df.format(started)) - .append("EndedEnded: ") .append(df.format(ended)) .append("

");