Skip to content

Commit

Permalink
Merge pull request DSpace#10358 from DSpace/backport-10293-to-dspace-7_x
Browse files Browse the repository at this point in the history
[Port dspace-7_x] Fix ClamAV curation task crashing on exceptions instead of ending gracefully
  • Loading branch information
tdonohue authored Feb 3, 2025
2 parents 6bf4d14 + 094af86 commit ec32897
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions dspace-api/src/main/java/org/dspace/ctask/general/ClamScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.dspace.authorize.AuthorizeException;
import org.apache.commons.collections4.ListUtils;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.DSpaceObject;
Expand Down Expand Up @@ -99,7 +98,12 @@ public int perform(DSpaceObject dso) throws IOException {
}

try {
Bundle bundle = itemService.getBundles(item, "ORIGINAL").get(0);
List<Bundle> bundles = itemService.getBundles(item, "ORIGINAL");
if (ListUtils.emptyIfNull(bundles).isEmpty()) {
setResult("No ORIGINAL bundle found for item: " + getItemHandle(item));
return Curator.CURATE_SKIP;
}
Bundle bundle = bundles.get(0);
results = new ArrayList<String>();
for (Bitstream bitstream : bundle.getBitstreams()) {
InputStream inputstream = bitstreamService.retrieve(Curator.curationContext(), bitstream);
Expand All @@ -121,10 +125,11 @@ public int perform(DSpaceObject dso) throws IOException {
}

}
} catch (AuthorizeException authE) {
throw new IOException(authE.getMessage(), authE);
} catch (SQLException sqlE) {
throw new IOException(sqlE.getMessage(), sqlE);
} catch (Exception e) {
// Any exception which may occur during the performance of the task should be caught here
// And end the process gracefully
log.error("Error scanning item: " + getItemHandle(item), e);
status = Curator.CURATE_ERROR;
} finally {
closeSession();
}
Expand Down

0 comments on commit ec32897

Please sign in to comment.