use md5sum on ini files to determine if they need re-writing
[pear] / HTML / FlexyFramework / Generator.php
index bda57c2..2f8280b 100644 (file)
@@ -168,9 +168,10 @@ class HTML_FlexyFramework_Generator extends DB_DataObject_Generator
     }
     /**
      * Generate the cached *.ini and links.ini files (merged for all components)
-     * 
+     * @param string $iniCacheTmp a temporary file
+     * @param string $iniCache the real target.
      */
-    static function writeCache($iniCacheTmp, $iniCache)
+    static function writeCache($iniCacheTmp, $iniCache, $replace = array())
     {
         
         $fp = fopen($iniCache.".lock", "a+");
@@ -182,14 +183,22 @@ class HTML_FlexyFramework_Generator extends DB_DataObject_Generator
         //var_dump($iniCacheTmp);
        // echo '<PRE>';echo file_get_contents($iniCacheTmp);exit;
         // only unpdate if nothing went wrong.
+        clearstatcace();
         if (file_exists($iniCacheTmp) && filesize($iniCacheTmp)) {
-            if (file_exists($iniCache)) {
-                unlink($iniCache);
+            // is the replace file exist?
+            if (!isset($replace[$iniCache]) || $replace[$iniCache] != md5_file($iniCacheTmp)) {
+            
+            
+                if (file_exists($iniCache)) {
+                    unlink($iniCache);
+                }
+                $ff->debug("Writing merged ini file : $iniCache\n");
+                rename($iniCacheTmp, $iniCache);
+            } else {
+                touch($iniCache);
             }
-            $ff->debug("Writing merged ini file : $iniCache\n");
-            rename($iniCacheTmp, $iniCache);
         }
-        
+        /*
         // readers..??? not needed??? (historical)
         if (file_exists($iniCacheTmp.'.reader') &&  filesize($iniCacheTmp.'.reader')) {
             if (file_exists($iniCache.'.reader')) {
@@ -198,7 +207,7 @@ class HTML_FlexyFramework_Generator extends DB_DataObject_Generator
             $ff->debug("Writing merged reader file : $iniCache.reader\n");
             rename($iniCacheTmp.'.reader', $iniCache.'.reader');
         }
-        
+        */
         
         // merge and set links.. test for generated links file..
         
@@ -259,13 +268,19 @@ class HTML_FlexyFramework_Generator extends DB_DataObject_Generator
         }
         if (count($out)) {
             $ff->debug("Writing merged Links file : $iniLinksCache \n");
-
-           
-            file_put_contents($iniCacheTmp. '.links.ini', implode("\n", $out));
-            if (file_exists($iniLinksCache)) {                
-                unlink($iniLinksCache);
+            $out_str = implode("\n", $out);
+            // is target file different?
+            if (!isset($replace[$iniLinksCache]) || $replace[$iniLinksCache] != md5($out)) {
+          
+                 file_put_contents($iniCacheTmp. '.links.ini', $out_str);
+                 if (file_exists($iniLinksCache)) {                
+                     unlink($iniLinksCache);
+                 }
+                 rename($iniCacheTmp. '.links.ini', $iniLinksCache);
+            } else {
+                touch($iniLinksCache);
+                
             }
-            rename($iniCacheTmp. '.links.ini', $iniLinksCache);
         }
         
         flock($fp, LOCK_UN);