Skip to content

Commit

Permalink
Pull up AbstractFolder.delete logic into AbstractItem
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Oct 25, 2023
1 parent c9947a3 commit 2688a49
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions core/src/main/java/hudson/model/AbstractItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import hudson.Util;
import hudson.XmlFile;
import hudson.cli.declarative.CLIResolver;
import hudson.model.Queue.Executable;
import hudson.model.listeners.ItemListener;
import hudson.model.listeners.SaveableListener;
import hudson.model.queue.SubTask;
Expand Down Expand Up @@ -748,7 +747,7 @@ public void delete() throws IOException, InterruptedException {
for (Computer c : Jenkins.get().getComputers()) {
for (Executor e : c.getAllExecutors()) {
final WorkUnit workUnit = e.getCurrentWorkUnit();
final Executable executable = workUnit != null ? workUnit.getExecutable() : null;
final Queue.Executable executable = workUnit != null ? workUnit.getExecutable() : null;
final SubTask subtask = executable != null ? getParentOf(executable) : null;

if (subtask != null) {
Expand Down Expand Up @@ -801,6 +800,24 @@ public void delete() throws IOException, InterruptedException {
}
}
}
if (this instanceof ItemGroup) {
// delete individual items first
// (disregard whether they would be deletable in isolation)
// JENKINS-34939: do not hold the monitor on this folder while deleting them
// (thus we cannot do this inside performDelete)
try (ACLContext oldContext = ACL.as2(ACL.SYSTEM2)) {
for (Item i : ((ItemGroup<?>) this).getItems(TopLevelItem.class::isInstance)) {
try {
i.delete();
} catch (AbortException e) {
throw (AbortException) new AbortException(
"Failed to delete " + i.getFullDisplayName() + " : " + e.getMessage()).initCause(e);
} catch (IOException e) {
throw new IOException("Failed to delete " + i.getFullDisplayName(), e);
}
}
}
}
synchronized (this) { // could just make performDelete synchronized but overriders might not honor that
performDelete();
} // JENKINS-19446: leave synch block, but JENKINS-22001: still notify synchronously
Expand Down

0 comments on commit 2688a49

Please sign in to comment.