Check the return value of File.delete()
Check the return value of File.delete() and throw an exception if deleting a file fails. Issue #4203
This commit is contained in:
committed by
Mahmoud Ben Hassine
parent
15f3637ac8
commit
8c7fb5ca02
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -270,7 +270,9 @@ public abstract class AbstractFileItemWriter<T> extends AbstractItemStreamItemWr
|
||||
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);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -735,7 +735,9 @@ public class StaxEventItemWriter<T> extends AbstractItemStreamItemWriter<T>
|
||||
}
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user