svn: /web/doc-editor/trunk/php/ SvnClient.php

[email protected] (Chan Ka Shing)
Newsgroups php.doc.web
Message-ID <[email protected]>
mrkschan                                 Mon, 26 Apr 2010 10:25:34 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=298586

Log:
bug fix: svn auth fail in firing two requests with a single socket, now it uses two separate sockets.
changes: propagates svn error checking to svn up.

Changed paths:
    U   web/doc-editor/trunk/php/SvnClient.php

Modified: web/doc-editor/trunk/php/SvnClient.php
===================================================================
--- web/doc-editor/trunk/php/SvnClient.php	2010-04-26 08:20:58 UTC (rev 298585)
+++ web/doc-editor/trunk/php/SvnClient.php	2010-04-26 10:25:34 UTC (rev 298586)
@@ -178,11 +178,12 @@
         do {
             if ($trial_count++ == 3) return 'svn login failed';
             fwrite($h, $ping);
-            $r = trim(fread($h, 1024));
+            $r = trim(fread($h, 2048));

             // connection may be closed, need retry
             $m = preg_match('/realm="(.+)", nonce="(.+)", .+ qop="(.+)"/', $r, $matches);
         } while (0 == $m);
+        fclose($h);

         $data = array(
             'request' => 'MKACTIVITY',
@@ -212,12 +213,12 @@

 ', $uri, $host, $username, $data['realm'], $data['nonce'], $uri, $response, $data['cnonce'], $data['qop']);

+        $h = @fsockopen($host, $port);
         fwrite($h, $pong);
-        $r = trim(fread($h, 1024));
-
+        $r = trim(fread($h, 2048));
         fclose($h);

-        if (preg_match('/HTTP\/1.1 201 Created/', $r)) {
+        if (preg_match('/HTTP\/1.[01] 201 Created/', $r)) {
             return true;
         } else {
             return 'Invalid Credentail';
@@ -262,7 +263,7 @@
      *  "svn up" on a single folder
      *
      * @param $path The path.
-     * @return True if this folder exist after the update processus, false otherwise.
+     * @return True if svn up does not report any error, false otherwise.
      */
     public function updateSingleFolder($path)
     {
@@ -272,20 +273,20 @@

         $cmd = 'cd '.$appConf[$project]['vcs.path'].'; svn up .'.$path;

+        $err = 1;
         $trial_threshold = 3;
-        while ($trial_threshold-- > 0) {
-            $output = array();
-            exec($cmd, $output);
-            if (strlen(trim(implode('', $output))) != 0) break;
+        $output = array();
+        for ($trial = 0; $err != 0 && $trial < $trial_threshold; ++$trial) {
+            array_push($output, "svn up trial #$trial\n");
+            exec("$cmd 2>&1", $output, $err); // if no err, err = 0
+            if ($err == 0) array_push($output, "Success.\n");
         }

-        if( is_dir($appConf[$project]['vcs.path'].$path) ) {
+        if ($err == 0) {
             return true;
         } else {
             return false;
         }
-
-
     }

     /**
@@ -294,7 +295,7 @@
      * @param $lang The lang of this file.
      * @param $path The path for this file.
      * @param $name The name of the file.
-     * @return True if this file exist after the update processus, false otherwise.
+     * @return True if svn up does not report any error, false otherwise.
      */
     public function updateSingleFile($lang, $path, $name)
     {
@@ -304,24 +305,25 @@

         $cmd = 'cd '.$appConf[$project]['vcs.path'].'; svn up '.$lang.$path.$name;

+        $err = 1;
         $trial_threshold = 3;
-        while ($trial_threshold-- > 0) {
-            $output = array();
-            exec($cmd, $output);
-            if (strlen(trim(implode('', $output))) != 0) break;
+        $output = array();
+        for ($trial = 0; $err != 0 && $trial < $trial_threshold; ++$trial) {
+            array_push($output, "svn up trial #$trial\n");
+            exec("$cmd 2>&1", $output, $err); // if no err, err = 0
+            if ($err == 0) array_push($output, "Success.\n");
         }

-        if( is_file($appConf[$project]['vcs.path'].$lang.$path.$name) ) {
+        if ($err == 0) {
             return true;
         } else {
             return false;
         }
-
-
     }

     /**
      *  svn up . under DOC_EDITOR_VCS_PATH
+     * @return True if svn up does not report any error, false otherwise.
      */
     public function update()
     {
@@ -329,14 +331,22 @@
         $appConf = $am->appConf;
         $project = $am->project;

-        $cmd = 'cd '.$appConf[$project]['vcs.path'].'; svn up .;';
+        $cmd = 'cd '.$appConf[$project]['vcs.path'].'; svn up .';

+        $err = 1;
         $trial_threshold = 3;
-        while ($trial_threshold-- > 0) {
-            $output = array();
-            exec($cmd, $output);
-            if (strlen(trim(implode('', $output))) != 0) break;
+        $output = array();
+        for ($trial = 0; $err != 0 && $trial < $trial_threshold; ++$trial) {
+            array_push($output, "svn up trial #$trial\n");
+            exec("$cmd 2>&1", $output, $err); // if no err, err = 0
+            if ($err == 0) array_push($output, "Success.\n");
         }
+
+        if ($err == 0) {
+            return true;
+        } else {
+            return false;
+        }
     }

     /**
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.