Skip to content

Commit

Permalink
Merged in task/dspace-cris-2023_02_x/DSC-1711_Export-process-failing-…
Browse files Browse the repository at this point in the history
…when-run-twice-on-the-same-item (pull request DSpace#2300)

Ensure work directory is cleaned up whether zip file is created successfully or an error occurs.

Approved-by: Giuseppe Digilio
  • Loading branch information
Mattia Vianelli authored and atarix83 committed Jun 13, 2024
2 parents 11f45cf + a658cf1 commit 12895e4
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 12895e4

Please sign in to comment.