Author: toad
Date: 2007-12-15 15:17:30 +0000 (Sat, 15 Dec 2007)
New Revision: 16572
Modified:
trunk/freenet/src/freenet/support/io/FileUtil.java
Log:
Check whether the file exists and is nonzero length before renaming it.
Modified: trunk/freenet/src/freenet/support/io/FileUtil.java
===================================================================
--- trunk/freenet/src/freenet/support/io/FileUtil.java 2007-12-15 15:15:13 UTC
(rev 16571)
+++ trunk/freenet/src/freenet/support/io/FileUtil.java 2007-12-15 15:17:30 UTC
(rev 16572)
@@ -149,6 +149,13 @@
// Shall we prevent symlink-race-conditions here ?
if(orig.equals(dest))
throw new IllegalArgumentException("Huh? the two file
descriptors are the same!");
+ if(!orig.exists()) {
+ throw new IllegalArgumentException("Original doesn't exist!");
+ }
+ if(orig.length() == 0) {
+ // 99% of the time this indicates a bug resulting in clobbering
files in zero disk space! If we need to support empty files anywhere we can add
an override.
+ throw new IllegalArgumentException("Original is empty!");
+ }
if (!orig.renameTo(dest)) {
// Not supported on some systems (Windows)
if (!dest.delete()) {