From 84a0e6930b8668a57075159d0c6e31e35e6c5e84 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20M=C3=BCller?= Date: Tue, 24 Sep 2013 15:35:21 +0200 Subject: [PATCH] creating non static getETagPropertyForPath() adding public $fileView to Node to allow unit testing --- lib/connector/sabre/directory.php | 5 ++--- lib/connector/sabre/file.php | 22 +++++++++++----------- lib/connector/sabre/node.php | 17 +++++++++++++++-- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index fa20a60f3a5..e36ac84652c 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -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; } diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php index aa71b8be217..af9a36931ab 100644 --- a/lib/connector/sabre/file.php +++ b/lib/connector/sabre/file.php @@ -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); } /** diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index 0bffa58af78..28679ef8026 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -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; + } } -- 2.39.5