Tweaks to improve ssh2 VFS performance
authorBen Klang <bklang@mojolingo.com>
Tue, 7 Dec 2010 22:16:26 +0000 (17:16 -0500)
committerBen Klang <bklang@mojolingo.com>
Tue, 7 Dec 2010 22:16:26 +0000 (17:16 -0500)
framework/VFS/lib/VFS/ssh2.php

index 00e5129..f4b14f9 100644 (file)
@@ -594,6 +594,24 @@ class VFS_ssh2 extends VFS
     }
 
     /**
+     * Returns if a given file or folder exists in a folder.
+     *
+     * @param string $path  The path to the folder.
+     * @param string $name  The file or folder name.
+     *
+     * @return boolean  True if it exists, false otherwise.
+     */
+    function exists($path, $name)
+    { 
+        $conn = $this->_connect();
+        if (is_a($conn, 'PEAR_Error')) {
+            return $conn;
+        }
+
+        return !(ssh2_sftp_stat($this->_sftp, ssh2_sftp_realpath($this->_sftp, $path) . '/' . $name) === false);
+    }
+
+    /**
      * Returns a sorted list of folders in the specified directory.
      *
      * @param string $path         The path of the directory to get the
@@ -870,7 +888,8 @@ class VFS_ssh2 extends VFS
     {
         return 'ssh2.sftp://' . $this->_params['username'] . ':' .
             $this->_params['password'] . '@' . $this->_params['hostspec'] .
-            ':' . $this->_params['port'] . $remote;
+            ':' . $this->_params['port'] .
+            ssh2_sftp_realpath($this->_sftp, $remote);
     }
 
 }