[freenet-cvs] r15056 - trunk/freenet/src/freenet/support/io

toad at freenetproject.org toad at freenetproject.org
Sat Sep 8 17:03:03 UTC 2007


Author: toad
Date: 2007-09-08 17:03:03 +0000 (Sat, 08 Sep 2007)
New Revision: 15056

Modified:
   trunk/freenet/src/freenet/support/io/FileUtil.java
Log:
Fix FileUtil.writeTo -> fix loading plugins via <plugin name># when the default temp dir and the data are on different drives or otherwise cannot be renamed.
Looks to have been a problem for a while.

Modified: trunk/freenet/src/freenet/support/io/FileUtil.java
===================================================================
--- trunk/freenet/src/freenet/support/io/FileUtil.java	2007-09-08 16:58:27 UTC (rev 15055)
+++ trunk/freenet/src/freenet/support/io/FileUtil.java	2007-09-08 17:03:03 UTC (rev 15056)
@@ -15,6 +15,7 @@
 import java.io.InputStreamReader;
 
 import freenet.client.DefaultMIMETypes;
+import freenet.support.Logger;
 
 final public class FileUtil {
 
@@ -107,7 +108,9 @@
 	public static boolean writeTo(InputStream input, File target) throws FileNotFoundException, IOException {
 		DataInputStream dis = null;
 		FileOutputStream fos = null;
-		File file = File.createTempFile("temp", ".tmp");
+		File file = File.createTempFile("temp", ".tmp", target.getParentFile());
+		if(Logger.shouldLog(Logger.MINOR, FileUtil.class))
+			Logger.minor(FileUtil.class, "Writing to "+file+" to be renamed to "+target);
 		
 		try {
 			dis = new DataInputStream(input);
@@ -125,7 +128,12 @@
 			if(fos != null) fos.close();
 		}
 		
-		return file.renameTo(target);
+		if(file.renameTo(target))
+			return true;
+		else {
+			file.delete();
+			return false;
+		}
 	}
 
 	public static String sanitize(String s) {




More information about the cvs mailing list