Skip to content

Commit

Permalink
Merge pull request DSpace#9637 from DSpace/backport-9629-to-dspace-7_x
Browse files Browse the repository at this point in the history
[Port dspace-7_x] Ensure work directory is cleaned up even when Zip export fails
  • Loading branch information
tdonohue authored Jun 6, 2024
2 parents 1769f16 + 95fc68b commit e899199
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -490,19 +490,26 @@ public void exportAsZip(Context context, Iterator<Item> items,

File wkDir = new File(workDir);
if (!wkDir.exists() && !wkDir.mkdirs()) {
logError("Unable to create working direcory");
logError("Unable to create working directory");
}

File dnDir = new File(destDirName);
if (!dnDir.exists() && !dnDir.mkdirs()) {
logError("Unable to create destination directory");
}

// export the items using normal export method
exportItem(context, items, workDir, seqStart, migrate, excludeBitstreams);
try {
// export the items using normal export method (this exports items to our workDir)
exportItem(context, items, workDir, seqStart, migrate, excludeBitstreams);

// now zip up the export directory created above
zip(workDir, destDirName + System.getProperty("file.separator") + zipFileName);
// now zip up the workDir directory created above
zip(workDir, destDirName + System.getProperty("file.separator") + zipFileName);
} finally {
// Cleanup workDir created above, if it still exists
if (wkDir.exists()) {
deleteDirectory(wkDir);
}
}
}

@Override
Expand Down

0 comments on commit e899199

Please sign in to comment.