[Pkg-owncloud-commits] [php-sabredav] 20/23: Updated code to use new path splitter instead of dirname/basename

David Prévot taffit at moszumanska.debian.org
Sat Nov 30 15:44:02 UTC 2013


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to tag version-1.0.12
in repository php-sabredav.

commit f36b0b259edf3647edd7bf5fc4482e5394c939c2
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Tue Mar 30 14:42:54 2010 +0900

    Updated code to use new path splitter instead of dirname/basename
---
 lib/Sabre/DAV/Browser/Plugin.php            | 11 ++++++++---
 lib/Sabre/DAV/Server.php                    |  8 ++++----
 lib/Sabre/DAV/TemporaryFileFilterPlugin.php |  5 +++--
 lib/Sabre/DAV/Tree.php                      | 15 +++++++++++----
 4 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/lib/Sabre/DAV/Browser/Plugin.php b/lib/Sabre/DAV/Browser/Plugin.php
index db1ce12..488b058 100644
--- a/lib/Sabre/DAV/Browser/Plugin.php
+++ b/lib/Sabre/DAV/Browser/Plugin.php
@@ -100,16 +100,21 @@ class Sabre_DAV_Browser_Plugin extends Sabre_DAV_ServerPlugin {
             case 'mkcol' :
                 if (isset($_POST['name']) && trim($_POST['name'])) {
                     // Using basename() because we won't allow slashes
-                    $folderName = trim(basename($_POST['name']));
+                    list(, $folderName) = Sabre_DAV_URLUtil::splitPath(trim($_POST['name']));
                     $this->server->createDirectory($this->server->getRequestUri() . '/' . $folderName);
                 }
                 break;
             case 'put' :
                 if ($_FILES) $file = current($_FILES);
                 else break;
-                $newName = basename($file['name']);
+                $newName = trim($file['name']);
+                list(, $newName) = Sabre_DAV_URLUtil::splitPath(trim($file['name']));
                 if (isset($_POST['name']) && trim($_POST['name']))
-                    $newName = trim(basename($_POST['name']));
+                    $newName = trim($_POST['name']);
+
+                // Making sure we only have a 'basename' component
+                list(, $newName) = Sabre_DAV_URLUtil::splitPath($newName);
+                    
                
                 if (is_uploaded_file($file['tmp_name'])) {
                     $parent = $this->server->tree->getNodeForPath(trim($this->server->getRequestUri(),'/'));
diff --git a/lib/Sabre/DAV/Server.php b/lib/Sabre/DAV/Server.php
index dafdae4..761297c 100644
--- a/lib/Sabre/DAV/Server.php
+++ b/lib/Sabre/DAV/Server.php
@@ -1010,13 +1010,13 @@ class Sabre_DAV_Server {
      */
     public function createFile($uri,$data) {
 
-        $parentUri = dirname($uri);
-        if ($parentUri=='.') $parentUri = '';
+        list($dir,$name) = Sabre_DAV_URLUtil::splitPath($uri);
+
         if (!$this->broadcastEvent('beforeBind',array($uri))) return;
         if (!$this->broadcastEvent('beforeCreateFile',array($uri,$data))) return;
 
-        $parent = $this->tree->getNodeForPath($parentUri);
-        $parent->createFile(basename($uri),$data);
+        $parent = $this->tree->getNodeForPath($dir);
+        $parent->createFile($name,$data);
 
         $this->broadcastEvent('afterBind',array($uri));
     }
diff --git a/lib/Sabre/DAV/TemporaryFileFilterPlugin.php b/lib/Sabre/DAV/TemporaryFileFilterPlugin.php
index ea80998..20cab64 100644
--- a/lib/Sabre/DAV/TemporaryFileFilterPlugin.php
+++ b/lib/Sabre/DAV/TemporaryFileFilterPlugin.php
@@ -134,11 +134,12 @@ class Sabre_DAV_TemporaryFileFilterPlugin extends Sabre_DAV_ServerPlugin {
      * temporary file storage.
      * 
      * @param string $path 
-     * @return mixed 
+     * @return boolean|string 
      */
     protected function isTempFile($path) {
 
-        $tempPath = basename($path);
+        // We're only interested in the basename.
+        list(, $tempPath) = Sabre_DAV_URLUtil::splitPath($path);
 
         $tempFiles = array(
             '/^\._(.*)$/',      // OS/X resource forks
diff --git a/lib/Sabre/DAV/Tree.php b/lib/Sabre/DAV/Tree.php
index 332473f..e00159f 100644
--- a/lib/Sabre/DAV/Tree.php
+++ b/lib/Sabre/DAV/Tree.php
@@ -32,8 +32,12 @@ abstract class Sabre_DAV_Tree {
     public function copy($sourcePath, $destinationPath) {
 
         $sourceNode = $this->getNodeForPath($sourcePath);
-        $destinationParent = $this->getNodeForPath(dirname($destinationPath));
-        $this->copyNode($sourceNode,$destinationParent,basename($destinationPath));
+       
+        // grab the dirname and basename components
+        list($destinationDir, $destinationName) = Sabre_DAV_URLUtil::splitPath($destinationPath);
+
+        $destinationParent = $this->getNodeForPath($destinationDir);
+        $this->copyNode($sourceNode,$destinationParent,$destinationName);
 
     }
 
@@ -46,9 +50,12 @@ abstract class Sabre_DAV_Tree {
      */
     public function move($sourcePath, $destinationPath) {
 
-        if (dirname($sourcePath)==dirname($destinationPath)) {
+        list($sourceDir, $sourceName) = Sabre_DAV_URLUtil::splitPath($sourcePath);
+        list($destinationDir, $destinationName) = Sabre_DAV_URLUtil::splitPath($destinationPath);
+
+        if ($sourceDir===$destinationDir) {
             $renameable = $this->getNodeForPath($sourcePath);
-            $renameable->setName(basename($destinationPath));
+            $renameable->setName($destinationName);
         } else {
             $this->copy($sourcePath,$destinationPath);
             $this->getNodeForPath($sourcePath)->delete();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list