CVS update: /cowiki/includes/cowiki/class/io/

[email protected] 28 Apr 2005 01:20:54 -0000
Newsgroups gmane.comp.php.cowiki.cvs
Message-ID <[email protected]>
User: dgorski 
Date: 2005/04/27 18:20:54

Modified:
   cowiki/includes/cowiki/class/io/class.FileOutputStream.php
   cowiki/includes/cowiki/class/io/class.AbstractOutputStream.php

Log:
 Pass locking strategy to the constructor

File Changes:

Directory: /cowiki/includes/cowiki/class/io/
============================================

File [changed]: class.FileOutputStream.php
Url: http://cowiki.tigris.org/source/browse/cowiki/includes/cowiki/class/io/class.FileOutputStream.php?r1=1.14&r2=1.15
Delta lines:  +23 -22
---------------------
--- class.FileOutputStream.php	19 Mar 2005 16:35:11 -0000	1.14
+++ class.FileOutputStream.php	28 Apr 2005 01:20:52 -0000	1.15
@@ -2,7 +2,7 @@
 
 /**
  *
- * $Id: class.FileOutputStream.php,v 1.14 2005/03/19 16:35:11 dgorski Exp $
+ * $Id: class.FileOutputStream.php,v 1.15 2005/04/28 01:20:52 dgorski Exp $
  *
  * This file is part of coWiki. coWiki is free software under the terms of
  * the GNU General Public License (GPL). Read the LICENSE file. If you did
@@ -17,7 +17,7 @@
  * @author      Daniel T. Gorski, <[email protected]>
  * @copyright   (C) Daniel T. Gorski, {@link http://www.develnet.org}
  * @license     http://www.gnu.org/licenses/gpl.html
- * @version     $Revision: 1.14 $
+ * @version     $Revision: 1.15 $
  *
  */
 
@@ -38,7 +38,8 @@
     protected
         $rFile     = null,
         $bOpener   = false,
-        $sLockfile = '';
+        $sLockType = '',
+        $sLockFile = '';
 
     // --------------------------------------------------------------------
 
@@ -48,6 +49,7 @@
      * @access  public
      * @param   object
      * @param   boolean
+     * @param   string
      * @return  void
      *
      * @author  Daniel T. Gorski, <[email protected]>
@@ -57,7 +59,10 @@
      *
      * @todo    [D11N]  Check the parameter type of "$mOut"
      */
-    public function __construct($mOut, $bAppend = false) {
+    public function __construct($mOut, $bAppend = false, $sLockType = 'STD') {
+
+        // Remember locking strategy ('STD', 'FILE', 'NONE')
+        $this->sLockType = $sLockType;
 
         if (is_string($mOut)) {
 
@@ -113,9 +118,7 @@
      */
     public function open($sFilename, $sMode) {
 
-        $Registry = RuntimeContext::getInstance()->getRegistry();
-
-        if ($Registry->get('RUNTIME_LOCKING_METHOD') == 'FILE') {
+        if ($this->sLockType == 'FILE') {
             if (!$this->lock($sFilename, LOCK_EX)) {
                 return false;
             }
@@ -125,7 +128,7 @@
             return false;
         }
 
-        if ($Registry->get('RUNTIME_LOCKING_METHOD') != 'FILE') {
+        if ($this->sLockType != 'FILE') {
             if (!$this->lock($this->rFile, LOCK_EX)) {
                 $this->close();
                 return false;
@@ -207,8 +210,7 @@
     // --------------------------------------------------------------------
 
     /**
-     * Lock
-     * Portable locking. Depending on settings in core.conf
+     * Portable locking depending passed on vlaues to the constructor.
      * STD  - Standard flock().
      * FILE - Uses lockfile.
      * NONE - No locking is performed.
@@ -225,11 +227,9 @@
      * @todo    [D11N]  Check description
      */
     private function lock($mFile, $iOperation) {
-
-        $Registry  = RuntimeContext::getInstance()->getRegistry();
         $bSuccess  = false;
 
-        switch ($Registry->get('RUNTIME_LOCKING_METHOD')) {
+        switch ($this->sLockType) {
 
             case 'NONE':
                 // No locking
@@ -238,25 +238,25 @@
 
             case 'FILE':
                 // dot-locking
-                if ($iOperation == LOCK_UN && !empty($this->sLockfile)) {
+                if ($iOperation == LOCK_UN && !empty($this->sLockFile)) {
 
-                    if (@unlink($this->sLockfile)) {
-                        $this->sLockfile = '';
+                    if (@unlink($this->sLockFile)) {
+                        $this->sLockFile = '';
                         $bSuccess = true;
                     }
 
                 } else {
 
-                    $sLockfile = $mFile.'.lock';
+                    $sLockFile = $mFile.'.lock';
                     if (function_exists('link')) {
-                        if (@link($mFile, $sLockfile)) {
-                            $this->sLockfile = $sLockfile;
+                        if (@link($mFile, $sLockFile)) {
+                            $this->sLockFile = $sLockFile;
                             $bSuccess = true;
                         }
                     } else {
-                        if ($rLock = @fopen($sLockfile, 'w')) {
+                        if ($rLock = @fopen($sLockFile, 'w')) {
                             @fclose($rLock);
-                            $this->sLockfile = $sLockfile;
+                            $this->sLockFile = $sLockFile;
                             $bSuccess = true;
                         }
                     }
@@ -265,10 +265,11 @@
                 break;
 
             case 'STD':
-            default: // this case includes null value
+            default:  // this case includes null/empty value
                 $bSuccess = @flock($mFile, $iOperation);
                 break;
         }
+
         return $bSuccess;
     }
 

File [changed]: class.AbstractOutputStream.php
Url: http://cowiki.tigris.org/source/browse/cowiki/includes/cowiki/class/io/class.AbstractOutputStream.php?r1=1.8&r2=1.9
Delta lines:  +4 -3
-------------------
--- class.AbstractOutputStream.php	17 Feb 2005 02:39:06 -0000	1.8
+++ class.AbstractOutputStream.php	28 Apr 2005 01:20:52 -0000	1.9
@@ -2,7 +2,7 @@
 
 /**
  *
- * $Id: class.AbstractOutputStream.php,v 1.8 2005/02/17 02:39:06 dgorski Exp $
+ * $Id: class.AbstractOutputStream.php,v 1.9 2005/04/28 01:20:52 dgorski Exp $
  *
  * This file is part of coWiki. coWiki is free software under the terms of
  * the GNU General Public License (GPL). Read the LICENSE file. If you did
@@ -17,7 +17,7 @@
  * @author      Daniel T. Gorski, <[email protected]>
  * @copyright   (C) Daniel T. Gorski, {@link http://www.develnet.org}
  * @license     http://www.gnu.org/licenses/gpl.html
- * @version     $Revision: 1.8 $
+ * @version     $Revision: 1.9 $
  *
  */
 
@@ -46,7 +46,8 @@
      *
      * @todo    [D11N]  Check description
      */
-    abstract public function __construct($mOut, $bAppend = false);
+    abstract public function __construct($mOut, $bAppend = false,
+                                         $sLockType = 'STD');
 
     // --------------------------------------------------------------------