Skip to content

Commit

Permalink
Fix atlassian API deleting the current version.
Browse files Browse the repository at this point in the history
It turns out that AttachmentManager.getPreviousVersions can actually return the current version.

I'm looking into finding out what conditions cause this but have for the moment put in protection to stop us deleting the current version.
  • Loading branch information
brettryan committed Mar 21, 2016
1 parent 250884d commit cd27b33
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.quartz.JobExecutionContext;
Expand All @@ -43,6 +44,7 @@
import static java.util.Comparator.nullsFirst;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
import static java.util.stream.Collectors.toSet;
import static org.apache.commons.lang.StringUtils.isNotBlank;
import static org.apache.commons.lang3.StringUtils.repeat;

Expand Down Expand Up @@ -163,7 +165,18 @@ public void doExecute(JobExecutionContext jec) throws JobExecutionException {
counters[IDX_PRIOR_VERSIONS] += prior.size();

List<Attachment> toDelete = findDeletions(prior, settings);
if (!toDelete.isEmpty()) {
Set<Integer> badVersions = toDelete.stream()
.filter(n -> n.getVersion() >= attachment.getVersion())
.map(n -> n.getVersion())
.collect(toSet());
if (badVersions.size() > 0) {
LOG.error("Attachment bas invalid prior versions: {}:{} :- {} ({}) :: {}",
attachment.getSpaceKey(),
attachment.getSpace().getName(),
attachment.getDisplayTitle(),
attachment.getVersion(),
badVersions);
} else if (!toDelete.isEmpty()) {
boolean canUpdate;
if (!settings.isReportOnly() && !systemSettings.isReportOnly()) {
canUpdate = systemSettings.getDeleteLimit() == 0 ||
Expand Down

0 comments on commit cd27b33

Please sign in to comment.