[Phpfreechat-svn] SF.net SVN: phpfreechat: [581] trunk/src
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-06-15 09:45:44
|
Revision: 581 Author: kerphi Date: 2006-06-15 02:45:32 -0700 (Thu, 15 Jun 2006) ViewCVS: http://svn.sourceforge.net/phpfreechat/?rev=581&view=rev Log Message: ----------- Bug fix: add a lock process when running the /rehash command in order to avoid run simultaneously two global config init step. Modified Paths: -------------- trunk/src/pfcglobalconfig.class.php trunk/src/pfctools.php Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2006-06-14 16:48:57 UTC (rev 580) +++ trunk/src/pfcglobalconfig.class.php 2006-06-15 09:45:32 UTC (rev 581) @@ -372,9 +372,14 @@ return $this->serverid; } + function _getCacheFile() + { + return $this->data_private_path."/cache/pfcglobalconfig_".$this->getId(); + } + function destroy() { - $cachefile = $this->data_private_path."/cache/pfcglobalconfig_".$this->getId(); + $cachefile = $this->_getCacheFile(); if (!file_exists($cachefile)) return false; $this->is_init = false; @@ -382,15 +387,19 @@ } /** - * save the pfcConfig object into cache if it doesn't exists yet + * Save the pfcConfig object into cache if it doesn't exists yet * else restore the old pfcConfig object */ function synchronizeWithCache() { - $cachefile = $this->data_private_path."/cache/pfcglobalconfig_".$this->getId(); - + $cachefile = $this->_getCacheFile(); + $cachefile_lock = $cachefile."_lock"; + if (file_exists($cachefile)) { + // if a cache file exists, remove the lock file because config has been succesfully stored + if (file_exists($cachefile_lock)) @unlink($cachefile_lock); + $pfc_configvar = unserialize(file_get_contents($cachefile)); foreach($pfc_configvar as $key => $val) $this->$key = $val; @@ -398,6 +407,11 @@ } else { + if (file_exists($cachefile_lock)) + return false; // do nothing if the lock file exists + else + @touch($cachefile_lock); // create the lockfile + if (!$this->isInit()) $this->init(); $errors =& $this->getErrors(); @@ -413,7 +427,7 @@ } function saveInCache() { - $cachefile = $this->data_private_path."/cache/pfcglobalconfig_".$this->getId(); + $cachefile = $this->_getCacheFile(); file_put_contents($cachefile, serialize(get_object_vars($this))); if ($this->debug) pxlog("pfcGlobalConfig::saveInCache()", "chatconfig", $this->getId()); } Modified: trunk/src/pfctools.php =================================================================== --- trunk/src/pfctools.php 2006-06-14 16:48:57 UTC (rev 580) +++ trunk/src/pfctools.php 2006-06-15 09:45:32 UTC (rev 581) @@ -132,7 +132,6 @@ * Copy a file, or recursively copy a folder and its contents * * @author Aidan Lister <ai...@ph...> - * @version 1.0.1 * @link http://aidanlister.com/repos/v/function.copyr.php * @param string $source Source path * @param string $dest Destination path @@ -143,7 +142,7 @@ // Simple copy for a file if (is_file($source)) { $ret = copy($source, $dest); - @chmod($dest, $mode); + chmod($dest, $mode); return $ret; } @@ -163,8 +162,8 @@ // Loop through the folder foreach ($entries as $e) { - // Skip pointers - if ($e == '.' || $e == '..') continue; + // Skip pointers and subversion directories + if ($e == '.' || $e == '..' || $e == '.svn') continue; // Deep copy directories if ($dest !== $source . DIRECTORY_SEPARATOR . $e) copyr($source . DIRECTORY_SEPARATOR . $e, $dest . DIRECTORY_SEPARATOR . $e, $mode); @@ -283,7 +282,6 @@ * @package PHP_Compat * @link http://php.net/function.file_put_contents * @author Aidan Lister <ai...@ph...> - * @version $Revision: 1.25 $ * @internal resource_context is not supported * @since PHP 5 * @require PHP 4.0.0 (user_error) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |