[pLog-svn] r1865 - in plog/branches/plog-1.0.1/class: file template

oscar at devel.plogworld.net oscar at devel.plogworld.net
Mon Apr 18 16:29:53 GMT 2005


Author: oscar
Date: 2005-04-18 16:29:53 +0000 (Mon, 18 Apr 2005)
New Revision: 1865

Modified:
   plog/branches/plog-1.0.1/class/file/file.class.php
   plog/branches/plog-1.0.1/class/template/cachecontrol.class.php
Log:
I just made a few changes that should improve the situation concerning safe_mode and all the folders that need to be created in the tmp/ folder. Basically, what this patch does is that even though folders are still required, it won't be removing and creating them once again every time the cache needs to be filled.

In other words, currently if we've got the folder tmp/4/ which is holding the cached templates of the blog with id 4, whenever the cache needs to be emptied for this blog we will remove the whole tmp/4/ folder, not just its contents. After that, a *new* folder called "4" is created once again and permissions are reset.

This patch allows to pre-create the folders once and forget about them so now it will be possible for people running php in safe mode to use plog with template caching enabled. The only pre-requisite is that the folders will need to be manually pre-created.

This patch needs a bit of testing and that's why I am committing it right away... that's the best way to get people to test things :)


Modified: plog/branches/plog-1.0.1/class/file/file.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/file/file.class.php	2005-04-18 13:37:28 UTC (rev 1864)
+++ plog/branches/plog-1.0.1/class/file/file.class.php	2005-04-18 16:29:53 UTC (rev 1865)
@@ -219,6 +219,9 @@
 		 {
 			 if( $file == null )
 				 $file = $this->_fileName;
+
+            if( !File::isReadable( $file ))
+                return false;
 			 
 			 if( File::isDir( $file ))
 				 $result = rmdir( $file );
@@ -232,10 +235,15 @@
 		  * removes a directory, optinally in a recursive fashion
 		  *
 		  * @param dirName
-		  * @param recursive
+		  * @param recursive Whether to recurse through all subdirectories that
+		  * are within the given one and remove them.
+		  * @param onlyFiles If the recursive mode is enabled, setting this to 'true' will
+		  * force the method to only remove files but not folders. The directory will not be
+		  * removed but all the files included it in (and all subdirectories) will be.
 		  * @return True if successful or false otherwise
+		  * @static
 		  */
-		 function deleteDir( $dirName, $recursive = false )
+		 function deleteDir( $dirName, $recursive = false, $onlyFiles = false )
 		 {
 			// if the directory can't be read, then quit with an error
 			if( !File::isReadable( $dirName ) || !File::exists( $dirName )) {
@@ -257,16 +265,17 @@
 				if( File::isDir( $file )) {
 					// perform a recursive call if we were allowed to do so
 					if( $recursive ) 
-						File::deleteDir( $file, $recursive );
+						File::deleteDir( $file, $recursive, $onlyFiles );
 				}
 				
 				// File::delete can remove empty folders as well as files
 				if( File::isReadable( $file ))
-					File::delete( $file );
-			}
+					File::delete( $file );			}
 			
-			// finally, remove the top-level folder
-			File::delete( $dirName );
+			// finally, remove the top-level folder but only in case we
+			// are supposed to!
+			if( !$onlyFiles )
+    			File::delete( $dirName );
 			
 			return true;
 		 }

Modified: plog/branches/plog-1.0.1/class/template/cachecontrol.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/template/cachecontrol.class.php	2005-04-18 13:37:28 UTC (rev 1864)
+++ plog/branches/plog-1.0.1/class/template/cachecontrol.class.php	2005-04-18 16:29:53 UTC (rev 1865)
@@ -54,7 +54,8 @@
 			$tmpFolder = $config->getValue( "temp_folder" );
 			$summaryTmpFolder = $tmpFolder."/summary";
 			
-			File::deleteDir( $summaryTmpFolder );
+			// delete the contents of the folder, but not its structure or subfolders
+			File::deleteDir( $summaryTmpFolder, true, true );
 			
 			return true;		
 		}
@@ -89,7 +90,8 @@
 			$blogTmpFolder = $tmpFolder."/".$blogId;
             //$t->cache_dir    = $blogTmpFolder;
             //$t->compile_dir  = $blogTmpFolder;
-			File::deleteDir( $blogTmpFolder, true );
+			// recursively delete the contents of the folder, but not its structure or subfolders            
+			File::deleteDir( $blogTmpFolder, true, true );
 			
 			//$t->clear_cache( null );
 			




More information about the pLog-svn mailing list