Merge pull request #9637 from DSpace/backport-9629-to-dspace-7_x

[Port dspace-7_x] Ensure work directory is cleaned up even when Zip export fails
This commit is contained in:
Tim Donohue
2024-06-06 10:44:27 -05:00
committed by GitHub

View File

@@ -490,7 +490,7 @@ public class ItemExportServiceImpl implements ItemExportService {
File wkDir = new File(workDir); File wkDir = new File(workDir);
if (!wkDir.exists() && !wkDir.mkdirs()) { if (!wkDir.exists() && !wkDir.mkdirs()) {
logError("Unable to create working direcory"); logError("Unable to create working directory");
} }
File dnDir = new File(destDirName); File dnDir = new File(destDirName);
@@ -498,11 +498,18 @@ public class ItemExportServiceImpl implements ItemExportService {
logError("Unable to create destination directory"); logError("Unable to create destination directory");
} }
// export the items using normal export method try {
// export the items using normal export method (this exports items to our workDir)
exportItem(context, items, workDir, seqStart, migrate, excludeBitstreams); exportItem(context, items, workDir, seqStart, migrate, excludeBitstreams);
// now zip up the export directory created above // now zip up the workDir directory created above
zip(workDir, destDirName + System.getProperty("file.separator") + zipFileName); zip(workDir, destDirName + System.getProperty("file.separator") + zipFileName);
} finally {
// Cleanup workDir created above, if it still exists
if (wkDir.exists()) {
deleteDirectory(wkDir);
}
}
} }
@Override @Override