]> source.dussan.org Git - nextcloud-server.git/commitdiff
creating non static getETagPropertyForPath()
authorThomas Müller <thomas.mueller@tmit.eu>
Tue, 24 Sep 2013 13:35:21 +0000 (15:35 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 24 Sep 2013 13:35:21 +0000 (15:35 +0200)
adding public $fileView to Node to allow unit testing

lib/connector/sabre/directory.php
lib/connector/sabre/file.php
lib/connector/sabre/node.php

index fa20a60f3a504999d53999c4b52566d119d69c64..e36ac84652c685e71965132dde7046673b66769d 100644 (file)
@@ -205,13 +205,12 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
         * If the array is empty, all properties should be returned
         *
         * @param array $properties
-        * @return void
+        * @return array
         */
        public function getProperties($properties) {
                $props = parent::getProperties($properties);
                if (in_array(self::GETETAG_PROPERTYNAME, $properties) && !isset($props[self::GETETAG_PROPERTYNAME])) {
-                       $props[self::GETETAG_PROPERTYNAME]
-                               = OC_Connector_Sabre_Node::getETagPropertyForPath($this->path);
+                       $props[self::GETETAG_PROPERTYNAME] = $this->getETagPropertyForPath($this->path);
                }
                return $props;
        }
index aa71b8be2170f01314647ccb74a668e88a21d19c..af9a36931ab2d6e38b6bd086d94b8510c7e3c135 100644 (file)
@@ -45,9 +45,9 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
         * @return string|null
         */
        public function put($data) {
-
-               if (\OC\Files\Filesystem::file_exists($this->path) &&
-                       !\OC\Files\Filesystem::isUpdatable($this->path)) {
+               $fs = $this->getFS();
+               if ($fs->file_exists($this->path) &&
+                       !$fs->isUpdatable($this->path)) {
                        throw new \Sabre_DAV_Exception_Forbidden();
                }
 
@@ -69,7 +69,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
                        if ($chunk_handler->isComplete()) {
                                $newPath = $this->path . '/' . $info['name'];
                                $chunk_handler->file_assemble($newPath);
-                               return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
+                               return $this->getETagPropertyForPath($newPath);
                        }
 
                        return null;
@@ -78,10 +78,10 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
                // mark file as partial while uploading (ignored by the scanner)
                $partpath = $this->path . '.part';
 
-               $putOkay = \OC\Files\Filesystem::file_put_contents($partpath, $data);
+               $putOkay = $fs->file_put_contents($partpath, $data);
                if ($putOkay === false) {
                        \OC_Log::write('webdav', '\OC\Files\Filesystem::file_put_contents() failed', \OC_Log::ERROR);
-                       \OC\Files\Filesystem::unlink($partpath);
+                       $fs->unlink($partpath);
                        throw new Sabre_DAV_Exception();
                }
 
@@ -89,9 +89,9 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
                if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) {
                        if (isset($_SERVER['CONTENT_LENGTH'])) {
                                $expected = $_SERVER['CONTENT_LENGTH'];
-                               $actual = \OC\Files\Filesystem::filesize($partpath);
+                               $actual = $fs->filesize($partpath);
                                if ($actual != $expected) {
-                                       \OC\Files\Filesystem::unlink($partpath);
+                                       $fs->unlink($partpath);
                                        throw new Sabre_DAV_Exception_BadRequest(
                                                'expected filesize ' . $expected . ' got ' . $actual);
                                }
@@ -99,17 +99,17 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
                }
 
                // rename to correct path
-               \OC\Files\Filesystem::rename($partpath, $this->path);
+               $fs->rename($partpath, $this->path);
 
                // allow sync clients to send the mtime along in a header
                $mtime = OC_Request::hasModificationTime();
                if ($mtime !== false) {
-                       if(\OC\Files\Filesystem::touch($this->path, $mtime)) {
+                       if($fs->touch($this->path, $mtime)) {
                                header('X-OC-MTime: accepted');
                        }
                }
 
-               return OC_Connector_Sabre_Node::getETagPropertyForPath($this->path);
+               return $this->getETagPropertyForPath($this->path);
        }
 
        /**
index 0bffa58af78b9efe3a3688c0afb749054b34a1e3..28679ef802682b2d7c064bbf2708d3c33b0ac6e6 100644 (file)
@@ -32,6 +32,13 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
        */
        public static $ETagFunction = null;
 
+       /**
+        * is kept public to allow overwrite for unit testing
+        *
+        * @var \OC\Files\View
+        */
+       public $fileView;
+
        /**
         * The path to the current node
         *
@@ -216,12 +223,18 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
         * @param string $path Path of the file
         * @return string|null Returns null if the ETag can not effectively be determined
         */
-       static public function getETagPropertyForPath($path) {
-               $data = \OC\Files\Filesystem::getFileInfo($path);
+       protected function getETagPropertyForPath($path) {
+               $data = $this->getFS()->getFileInfo($path);
                if (isset($data['etag'])) {
                        return '"'.$data['etag'].'"';
                }
                return null;
        }
 
+       protected function getFS() {
+               if (is_null($this->fileView)) {
+                       $this->fileView = \OC\Files\Filesystem::getView();
+               }
+               return $this->fileView;
+       }
 }