This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 12f292fcbd8 CAMEL-19493:cleanups: review and replace File#delete with
Files#delete (#11403)
12f292fcbd8 is described below
commit 12f292fcbd83576c4e4d6aa3bf7ce62a3d58a62f
Author: TUCJVXCB <[email protected]>
AuthorDate: Fri Sep 15 18:15:08 2023 +0800
CAMEL-19493:cleanups: review and replace File#delete with Files#delete
(#11403)
Co-authored-by: tanyu <[email protected]>
---
.../main/java/org/apache/camel/util/FileUtil.java | 26 ++++++++++++++--------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/FileUtil.java
b/core/camel-util/src/main/java/org/apache/camel/util/FileUtil.java
index e8d24b9f5d3..e6260c3fa7f 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/FileUtil.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/FileUtil.java
@@ -379,13 +379,17 @@ public final class FileUtil {
}
private static void delete(File f) {
- if (!f.delete()) {
+ try {
+ Files.delete(f.toPath());
+ } catch (IOException e) {
try {
Thread.sleep(RETRY_SLEEP_MILLIS);
} catch (InterruptedException ex) {
// Ignore Exception
}
- if (!f.delete()) {
+ try {
+ Files.delete(f.toPath());
+ } catch (IOException ex) {
f.deleteOnExit();
}
}
@@ -461,7 +465,7 @@ public final class FileUtil {
if (!deleteFile(from)) {
throw new IOException(
"Renaming file from '" + from + "' to '" + to + "' failed:
Cannot delete file '" + from
- + "' after copy succeeded");
+ + "' after copy succeeded");
}
return true;
@@ -499,12 +503,16 @@ public final class FileUtil {
while (!deleted && count < 3) {
LOG.debug("Retrying attempt {} to delete file: {}", count, file);
- deleted = file.delete();
- if (!deleted && count > 0) {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // ignore
+ try {
+ Files.delete(file.toPath());
+ deleted = true;
+ } catch (IOException e) {
+ if (count > 0) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ie) {
+ // ignore
+ }
}
}
count++;