diff options
| author | Martin Ritchie <ritchiem@apache.org> | 2009-03-09 09:40:13 +0000 |
|---|---|---|
| committer | Martin Ritchie <ritchiem@apache.org> | 2009-03-09 09:40:13 +0000 |
| commit | d88ca1b36ba61b24b3a6980583593c9f3997c0f9 (patch) | |
| tree | 70eaec0e7d8caa378effb8e16da27490ede9bbb9 /qpid/java | |
| parent | d589adc370fbc468979809ecbffd1bf3e03e0a80 (diff) | |
| download | qpid-python-d88ca1b36ba61b24b3a6980583593c9f3997c0f9.tar.gz | |
FileUtils would report a failure to delete a non-existent file
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@751636 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
| -rw-r--r-- | qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java | 4 | ||||
| -rw-r--r-- | qpid/java/common/src/test/java/org/apache/qpid/util/FileUtilsTest.java | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java b/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java index 585657c8bb..029e298c32 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java @@ -247,7 +247,7 @@ public class FileUtils boolean success = true; // If we have nothing to delete then it must be ok to say it was deleted. - if (file == null) + if (file == null || !file.exists()) { return true; } @@ -258,7 +258,7 @@ public class FileUtils { for (File subFile : file.listFiles()) { - success = delete(subFile, true) & success ; + success = delete(subFile, true) && success; } return success && file.delete(); diff --git a/qpid/java/common/src/test/java/org/apache/qpid/util/FileUtilsTest.java b/qpid/java/common/src/test/java/org/apache/qpid/util/FileUtilsTest.java index fb367d042c..76d39200c1 100644 --- a/qpid/java/common/src/test/java/org/apache/qpid/util/FileUtilsTest.java +++ b/qpid/java/common/src/test/java/org/apache/qpid/util/FileUtilsTest.java @@ -280,6 +280,16 @@ public class FileUtilsTest extends TestCase checkFileLists(filesBefore, filesAfter); } + public void testDeleteNonExistentFile() + { + File test = new File("FileUtilsTest-testDelete-"+System.currentTimeMillis()); + + assertTrue("File exists", !test.exists()); + assertFalse("File is a directory", test.isDirectory()); + + assertTrue("Unable to delete",FileUtils.delete(test,true)); + } + /** * Given two lists of File arrays ensure they are the same length and all entries in Before are in After * |
