Skip to content

Commit

Permalink
Ensure work directory is cleaned up whether zip file is created succe…
Browse files Browse the repository at this point in the history
…ssfully or an error occurs.
  • Loading branch information
tdonohue authored and Mattia Vianelli committed Jun 12, 2024
1 parent a301d36 commit a658cf1
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 a658cf1

Please sign in to comment.