diff options
author | Alexander Nittka <alex@nittka.de> | 2020-03-13 14:16:50 +0100 |
---|---|---|
committer | Thomas Wolf <thomas.wolf@paranor.ch> | 2020-04-03 19:30:31 +0200 |
commit | bc4ed530a5f19b5dae77f3aa76369003bd6c3599 (patch) | |
tree | 26f0092c372d7307589a071d83e550ed4365353a /org.eclipse.jgit.test/tst | |
parent | 9aaa58052b4f810da7a1b3cd67dadbd50e956934 (diff) | |
download | jgit-bc4ed530a5f19b5dae77f3aa76369003bd6c3599.tar.gz jgit-bc4ed530a5f19b5dae77f3aa76369003bd6c3599.zip |
FileUtils: improve delete (Windows)
Ensure files are writable before trying to delete them.
Bug: 408846
Change-Id: I930a547594bba853c33634ae54bd64d236afade3
Signed-off-by: Alexander Nittka <alex@nittka.de>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilsTest.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilsTest.java index f9ec5d8d6f..2b1fb2ef04 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilsTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilsTest.java @@ -79,6 +79,15 @@ public class FileUtilsTest { } @Test + public void testDeleteReadOnlyFile() throws IOException { + File f = new File(trash, "f"); + FileUtils.createNewFile(f); + assertTrue(f.setReadOnly()); + FileUtils.delete(f); + assertFalse(f.exists()); + } + + @Test public void testDeleteRecursive() throws IOException { File f1 = new File(trash, "test/test/a"); FileUtils.mkdirs(f1.getParentFile()); @@ -339,6 +348,34 @@ public class FileUtilsTest { } @Test + public void testDeleteNonRecursiveTreeNotOk() throws IOException { + File t = new File(trash, "t"); + FileUtils.mkdir(t); + File f = new File(t, "f"); + FileUtils.createNewFile(f); + try { + FileUtils.delete(t, FileUtils.EMPTY_DIRECTORIES_ONLY); + fail("expected failure to delete f"); + } catch (IOException e) { + assertTrue(e.getMessage().endsWith(t.getAbsolutePath())); + } + assertTrue(f.exists()); + assertTrue(t.exists()); + } + + @Test + public void testDeleteNonRecursiveTreeIgnoreError() throws IOException { + File t = new File(trash, "t"); + FileUtils.mkdir(t); + File f = new File(t, "f"); + FileUtils.createNewFile(f); + FileUtils.delete(t, + FileUtils.EMPTY_DIRECTORIES_ONLY | FileUtils.IGNORE_ERRORS); + assertTrue(f.exists()); + assertTrue(t.exists()); + } + + @Test public void testRenameOverNonExistingFile() throws IOException { File d = new File(trash, "d"); FileUtils.mkdirs(d); |