Author: niallp
Date: Wed Jan 2 20:47:17 2008
New Revision: 608338
URL: http://svn.apache.org/viewvc?rev=608338&view=rev
Log:
IO-147 - Deletion of orphaned Softlinks does not work - reported by Stefan
Lischke, patch from Sebb
Modified:
commons/proper/io/trunk/RELEASE-NOTES.txt
commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java
Modified: commons/proper/io/trunk/RELEASE-NOTES.txt
URL:
http://svn.apache.org/viewvc/commons/proper/io/trunk/RELEASE-NOTES.txt?rev=608338&r1=608337&r2=608338&view=diff
==============================================================================
--- commons/proper/io/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/io/trunk/RELEASE-NOTES.txt Wed Jan 2 20:47:17 2008
@@ -26,6 +26,8 @@
Bug fixes from 1.3.2
--------------------
+- FileUtils
+ - forceDelete of orphaned Softlinks does not work [IO-147]
Enhancements from 1.3.2
-----------------------
Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
URL:
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java?rev=608338&r1=608337&r2=608338&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java Wed
Jan 2 20:47:17 2008
@@ -1232,16 +1232,18 @@
*
* @param file file or directory to delete, must not be <code>null</code>
* @throws NullPointerException if the directory is <code>null</code>
+ * @throws FileNotFoundException if the file was not found
* @throws IOException in case deletion is unsuccessful
*/
public static void forceDelete(File file) throws IOException {
if (file.isDirectory()) {
deleteDirectory(file);
} else {
- if (!file.exists()) {
- throw new FileNotFoundException("File does not exist: " +
file);
- }
+ boolean filePresent = file.exists();
if (!file.delete()) {
+ if (!filePresent){
+ throw new FileNotFoundException("File does not exist: " +
file);
+ }
String message =
"Unable to delete file: " + file;
throw new IOException(message);
Modified:
commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java
URL:
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java?rev=608338&r1=608337&r2=608338&view=diff
==============================================================================
---
commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java
(original)
+++
commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java
Wed Jan 2 20:47:17 2008
@@ -18,6 +18,7 @@
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -778,6 +779,16 @@
assertTrue("Copy2.txt doesn't exist to delete", destination.exists());
FileUtils.forceDelete(destination);
assertTrue("Check No Exist", !destination.exists());
+ }
+
+ public void testForceDeleteAFile3() throws Exception {
+ File destination = new File(getTestDirectory(), "no_such_file");
+ assertTrue("Check No Exist", !destination.exists());
+ try {
+ FileUtils.forceDelete(destination);
+ fail("Should generate FileNotFoundException");
+ } catch (FileNotFoundException ignored){
+ }
}
// copyFileToDirectory