[freenet-cvs] r12582 - in trunk/freenet/src/freenet: node support/io

nextgens at freenetproject.org nextgens at freenetproject.org
Wed Apr 11 18:33:07 UTC 2007


Author: nextgens
Date: 2007-04-11 18:33:07 +0000 (Wed, 11 Apr 2007)
New Revision: 12582

Modified:
   trunk/freenet/src/freenet/node/NodeClientCore.java
   trunk/freenet/src/freenet/support/io/FileUtil.java
Log:
move NodeClientCore.isParent(File, File) to where it belongs => FileUtil

Modified: trunk/freenet/src/freenet/node/NodeClientCore.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeClientCore.java	2007-04-11 17:04:47 UTC (rev 12581)
+++ trunk/freenet/src/freenet/node/NodeClientCore.java	2007-04-11 18:33:07 UTC (rev 12582)
@@ -48,6 +48,7 @@
 import freenet.support.api.BucketFactory;
 import freenet.support.api.StringArrCallback;
 import freenet.support.api.StringCallback;
+import freenet.support.io.FileUtil;
 import freenet.support.io.FilenameGenerator;
 import freenet.support.io.PaddedEphemerallyEncryptedBucketFactory;
 import freenet.support.io.PersistentEncryptedTempBucketFactory;
@@ -974,10 +975,10 @@
 	public boolean allowDownloadTo(File filename) {
 		if(downloadAllowedEverywhere) return true;
 		if(includeDownloadDir) {
-			if(isParent(downloadDir, filename)) return true;
+			if(FileUtil.isParent(downloadDir, filename)) return true;
 		}
 		for(int i=0;i<downloadAllowedDirs.length;i++) {
-			if(isParent(downloadAllowedDirs[i], filename)) return true;
+			if(FileUtil.isParent(downloadAllowedDirs[i], filename)) return true;
 		}
 		return false;
 	}
@@ -985,42 +986,11 @@
 	public boolean allowUploadFrom(File filename) {
 		if(uploadAllowedEverywhere) return true;
 		for(int i=0;i<uploadAllowedDirs.length;i++) {
-			if(isParent(uploadAllowedDirs[i], filename)) return true;
+			if(FileUtil.isParent(uploadAllowedDirs[i], filename)) return true;
 		}
 		return false;
 	}
 
-	/** Is possParent a parent of filename?
-	 * FIXME Move somewhere generic. 
-	 * Why doesn't java provide this? :( */
-	private boolean isParent(File possParent, File filename) {
-		File canonParent;
-		File canonFile;
-		try {
-			canonParent = possParent.getCanonicalFile();
-		} catch (IOException e) {
-			canonParent = possParent.getAbsoluteFile();
-		}
-		try {
-			canonFile = filename.getCanonicalFile();
-		} catch (IOException e) {
-			canonFile = filename.getAbsoluteFile();
-		}
-		if(isParentInner(possParent, filename)) return true;
-		if(isParentInner(possParent, canonFile)) return true;
-		if(isParentInner(canonParent, filename)) return true;
-		if(isParentInner(canonParent, canonFile)) return true;
-		return false;
-	}
-
-	private boolean isParentInner(File possParent, File filename) {
-		while(true) {
-			if(filename.equals(possParent)) return true;
-			filename = filename.getParentFile();
-			if(filename == null) return false;
-		}
-	}
-
 	public SimpleFieldSet persistThrottlesToFieldSet() {
 		return requestStarters.persistToFieldSet();
 	}

Modified: trunk/freenet/src/freenet/support/io/FileUtil.java
===================================================================
--- trunk/freenet/src/freenet/support/io/FileUtil.java	2007-04-11 17:04:47 UTC (rev 12581)
+++ trunk/freenet/src/freenet/support/io/FileUtil.java	2007-04-11 18:33:07 UTC (rev 12582)
@@ -4,6 +4,7 @@
 package freenet.support.io;
 
 import java.io.File;
+import java.io.IOException;
 
 final public class FileUtil {
 
@@ -12,7 +13,7 @@
 		int mask=blocksize-1;
 		return (val+mask)&~mask;
 	}
-	
+
 	/**
 	 * Guesstimate real disk usage for a file with a given filename, of a given length.
 	 */
@@ -31,4 +32,35 @@
 		long extra = (roundup_2n(flen, 1024) / 1024) * 50;
 		return blockUsage + filenameUsage + extra;
 	}
+
+	/** Is possParent a parent of filename?
+	 * FIXME Move somewhere generic. 
+	 * Why doesn't java provide this? :( */
+	public static boolean isParent(File possParent, File filename) {
+		File canonParent;
+		File canonFile;
+		try {
+			canonParent = possParent.getCanonicalFile();
+		} catch (IOException e) {
+			canonParent = possParent.getAbsoluteFile();
+		}
+		try {
+			canonFile = filename.getCanonicalFile();
+		} catch (IOException e) {
+			canonFile = filename.getAbsoluteFile();
+		}
+		if(isParentInner(possParent, filename)) return true;
+		if(isParentInner(possParent, canonFile)) return true;
+		if(isParentInner(canonParent, filename)) return true;
+		if(isParentInner(canonParent, canonFile)) return true;
+		return false;
+	}
+
+	private static boolean isParentInner(File possParent, File filename) {
+		while(true) {
+			if(filename.equals(possParent)) return true;
+			filename = filename.getParentFile();
+			if(filename == null) return false;
+		}
+	}
 }




More information about the cvs mailing list