From: Robin Appelman Date: Mon, 26 Jan 2015 16:48:28 +0000 (+0100) Subject: Fix webdav put for single file webdav shares X-Git-Tag: v8.0.0RC1~11^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=05035ef4af2222f67bb10e26f096e7eab04dfc17;p=nextcloud-server.git Fix webdav put for single file webdav shares --- diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index 0f5a3315f8f..12ce633838f 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -64,7 +64,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\ throw new \Sabre\DAV\Exception\ServiceUnavailable("Encryption is disabled"); } - $fileName = basename($this->path); + $fileName = basename($this->info->getPath()); if (!\OCP\Util::isValidFileName($fileName)) { throw new \Sabre\DAV\Exception\BadRequest(); } @@ -74,8 +74,8 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\ return $this->createFileChunked($data); } - list($storage, ) = $this->fileView->resolvePath($this->path); - $needsPartFile = $this->needsPartFile($storage); + list($storage,) = $this->fileView->resolvePath($this->path); + $needsPartFile = $this->needsPartFile($storage) && (strlen($this->path) > 1); if ($needsPartFile) { // mark file as partial while uploading (ignored by the scanner) diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php index 6bb1b4e75d1..33dc78f87d8 100644 --- a/tests/lib/connector/sabre/file.php +++ b/tests/lib/connector/sabre/file.php @@ -32,6 +32,31 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase { $file->put('test data'); } + public function testPutSingleFileShare() { + // setup + $storage = $this->getMock('\OCP\Files\Storage'); + $view = $this->getMock('\OC\Files\View', array('file_put_contents', 'getRelativePath'), array()); + $view->expects($this->any()) + ->method('resolvePath') + ->with('') + ->will($this->returnValue(array($storage, ''))); + $view->expects($this->any()) + ->method('getRelativePath') + ->will($this->returnValue('')); + $view->expects($this->any()) + ->method('file_put_contents') + ->with('') + ->will($this->returnValue(true)); + + $info = new \OC\Files\FileInfo('/foo.txt', null, null, array( + 'permissions' => \OCP\Constants::PERMISSION_ALL + ), null); + + $file = new OC_Connector_Sabre_File($view, $info); + + $this->assertNotEmpty($file->put('test data')); + } + /** * @expectedException \Sabre\DAV\Exception */