[pLog-svn] r1714 - plog/branches/plog-1.1-ben/class/cache/Cache_Lite

ork at devel.plogworld.net ork at devel.plogworld.net
Mon Apr 4 19:54:49 GMT 2005


Author: ork
Date: 2005-04-04 19:54:48 +0000 (Mon, 04 Apr 2005)
New Revision: 1714

Modified:
   plog/branches/plog-1.1-ben/class/cache/Cache_Lite/Lite.php
Log:
this should fix the initial fopen error message .. 


Modified: plog/branches/plog-1.1-ben/class/cache/Cache_Lite/Lite.php
===================================================================
--- plog/branches/plog-1.1-ben/class/cache/Cache_Lite/Lite.php	2005-04-04 19:33:57 UTC (rev 1713)
+++ plog/branches/plog-1.1-ben/class/cache/Cache_Lite/Lite.php	2005-04-04 19:54:48 UTC (rev 1714)
@@ -664,36 +664,36 @@
     */
     function _write($data)
     {
-        $try = 1;
-        while ($try<=2) {
-            $fp = @fopen($this->_file, "wb");
-            if ($fp) {
-                if ($this->_fileLocking) @flock($fp, LOCK_EX);
-                if ($this->_readControl) {
-                    @fwrite($fp, $this->_hash($data, $this->_readControlType), 32);
-                }
-                $len = strlen($data);
-                @fwrite($fp, $data, $len);
-                if ($this->_fileLocking) @flock($fp, LOCK_UN);
-                @fclose($fp);
-                return true;
-            } else {
-                if (($try==1) and ($this->_hashedDirectoryLevel>0)) {
-                    $hash = md5($this->_fileName);
-                    $root = $this->_cacheDir;
-                    for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) {
-                        $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/';
-                        @mkdir($root, 0700);
-                    }
-                    $try = 2;
-                } else {
-                    $try = 999;
-                }
+        $this->_createCacheDir();
+        $fp = @fopen($this->_file, 'w');
+        if ($fp) {
+            if ($this->_fileLocking) @flock($fp, LOCK_EX);
+            if ($this->_readControl) {
+                @fwrite($fp, $this->_hash($data, $this->_readControlType), 32);
             }
+            $len = strlen($data);
+            @fwrite($fp, $data, $len);
+            if ($this->_fileLocking) @flock($fp, LOCK_UN);
+            @fclose($fp);
+            return true;
         }
         $this->raiseError('Cache_Lite : Unable to write cache file : '.$this->_file, -1);
         return false;
     }
+
+    function _createCacheDir()
+    {
+        if (($this->_hashedDirectoryLevel>0)) {
+            $hash = md5($this->_fileName);
+            $root = $this->_cacheDir;
+            for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) {
+                $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/';
+                if (!is_dir($root)) {
+                    @mkdir($root, 0700);
+                }
+            }
+        }
+    }
     
     /**
     * Write the given data in the cache file and control it just after to avoir corrupted cache entries




More information about the pLog-svn mailing list