[freenet-cvs] r12597 - trunk/freenet/src/freenet/node/fcp

nextgens at freenetproject.org nextgens at freenetproject.org
Thu Apr 12 10:34:16 UTC 2007


Author: nextgens
Date: 2007-04-12 10:34:16 +0000 (Thu, 12 Apr 2007)
New Revision: 12597

Modified:
   trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
Log:
Trivial refactoring, share some duplicated code

Modified: trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java	2007-04-12 10:24:29 UTC (rev 12596)
+++ trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java	2007-04-12 10:34:16 UTC (rev 12597)
@@ -288,22 +288,14 @@
 	public boolean hasFullAccess() {
 		return server.allowedHostsFullAccess.allowed(sock.getInetAddress());
 	}
-	
-	protected boolean allowDownloadTo(File filename) {
-		String parentDirectory = FileUtil.getCanonicalFile(filename).getPath();
-		DirectoryAccess da = null;
-		
-		synchronized (checkedDirectories) {
-				da = (DirectoryAccess) checkedDirectories.get(parentDirectory);
-		}
-		
-		if(da == null)
-			return ASSUME_DOWNLOAD_DDA_IS_ALLOWED;
-		else
-			return da.canWrite;
-	}
 
-	protected boolean allowUploadFrom(File filename) {
+	/**
+	 * That method ought to be called before any DirectDiskAccess operation is performed by the node
+	 * @param filename
+	 * @param writeRequest : Are willing to write or to read ?
+	 * @return boolean : allowed or not
+	 */
+	protected boolean allowUploadFrom(File filename, boolean writeRequest) {
 		String parentDirectory = FileUtil.getCanonicalFile(filename).getPath();
 		DirectoryAccess da = null;
 		
@@ -311,10 +303,10 @@
 				da = (DirectoryAccess) checkedDirectories.get(parentDirectory);
 		}
 		
-		if(da == null)
-			return ASSUME_UPLOAD_DDA_IS_ALLOWED;
+		if(writeRequest)
+			return (da == null ? ASSUME_UPLOAD_DDA_IS_ALLOWED : da.canWrite);
 		else
-			return da.canRead;
+			return (da == null ? ASSUME_DOWNLOAD_DDA_IS_ALLOWED : da.canRead);
 	}
 	
 	/**




More information about the cvs mailing list