diff options
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java index 9f7d9a236e..4d791e470a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java @@ -48,6 +48,7 @@ package org.eclipse.jgit.util; import static java.nio.charset.StandardCharsets.UTF_8; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.nio.channels.FileChannel; import java.nio.file.AtomicMoveNotSupportedException; @@ -200,31 +201,50 @@ public class FileUtils { if ((options & EMPTY_DIRECTORIES_ONLY) != 0) { if (f.isDirectory()) { delete = true; - } else { - if ((options & IGNORE_ERRORS) == 0) - throw new IOException(MessageFormat.format( - JGitText.get().deleteFileFailed, - f.getAbsolutePath())); + } else if ((options & IGNORE_ERRORS) == 0) { + throw new IOException(MessageFormat.format( + JGitText.get().deleteFileFailed, f.getAbsolutePath())); } } else { delete = true; } - if (delete && !f.delete()) { - if ((options & RETRY) != 0 && fs.exists(f)) { + if (delete) { + Throwable t = null; + Path p = f.toPath(); + try { + Files.delete(p); + return; + } catch (FileNotFoundException e) { + if ((options & (SKIP_MISSING | IGNORE_ERRORS)) == 0) { + throw new IOException(MessageFormat.format( + JGitText.get().deleteFileFailed, + f.getAbsolutePath()), e); + } + return; + } catch (IOException e) { + t = e; + } + if ((options & RETRY) != 0) { for (int i = 1; i < 10; i++) { try { Thread.sleep(100); - } catch (InterruptedException e) { + } catch (InterruptedException ex) { // ignore } - if (f.delete()) + try { + Files.deleteIfExists(p); return; + } catch (IOException e) { + t = e; + } } } - if ((options & IGNORE_ERRORS) == 0) + if ((options & IGNORE_ERRORS) == 0) { throw new IOException(MessageFormat.format( - JGitText.get().deleteFileFailed, f.getAbsolutePath())); + JGitText.get().deleteFileFailed, f.getAbsolutePath()), + t); + } } } |