Skip to content

Commit

Permalink
Check the return value of File.delete()
Browse files Browse the repository at this point in the history
Check the return value of File.delete() and throw an exception if deleting a
file fails.
  • Loading branch information
marschall committed Dec 5, 2022
1 parent 656e3f8 commit 8ee023b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Expand Up @@ -270,7 +270,9 @@ public void close() {
state.close();
if (state.linesWritten == 0 && shouldDeleteIfEmpty) {
try {
resource.getFile().delete();
if (!resource.getFile().delete()) {
throw new ItemStreamException("Failed to delete empty file on close");
}
}
catch (IOException e) {
throw new ItemStreamException("Failed to delete empty file on close", e);
Expand Down
Expand Up @@ -735,7 +735,9 @@ public void close() {
}
if (currentRecordCount == 0 && shouldDeleteIfEmpty) {
try {
resource.getFile().delete();
if (!resource.getFile().delete()) {
throw new ItemStreamException("Failed to delete empty file on close");
}
}
catch (IOException e) {
throw new ItemStreamException("Failed to delete empty file on close", e);
Expand Down

0 comments on commit 8ee023b

Please sign in to comment.