From ddee63fa00e13e1830aa4b6113d30f24b3b34535 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 26 Jan 2015 17:48:09 +0100 Subject: [PATCH 1/2] Fix resolving paths for views rooted in a file --- lib/private/files/filesystem.php | 2 +- tests/lib/files/view.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php index c460159ece..140d892652 100644 --- a/lib/private/files/filesystem.php +++ b/lib/private/files/filesystem.php @@ -293,7 +293,7 @@ class Filesystem { } $mount = self::$mounts->find($path); if ($mount) { - return array($mount->getStorage(), $mount->getInternalPath($path)); + return array($mount->getStorage(), rtrim($mount->getInternalPath($path), '/')); } else { return array(null, null); } diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 158c964fd0..5e42e5ffd0 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -729,6 +729,22 @@ class View extends \Test\TestCase { ); } + public function testFileView() { + $storage = new Temporary(array()); + $scanner = $storage->getScanner(); + $storage->file_put_contents('foo.txt', 'bar'); + \OC\Files\Filesystem::mount($storage, array(), '/test/'); + $scanner->scan(''); + $view = new \OC\Files\View('/test/foo.txt'); + + $this->assertEquals('bar', $view->file_get_contents('')); + $fh = tmpfile(); + fwrite($fh, 'foo'); + rewind($fh); + $view->file_put_contents('', $fh); + $this->assertEquals('foo', $view->file_get_contents('')); + } + /** * @dataProvider tooLongPathDataProvider * @expectedException \OCP\Files\InvalidPathException From 05035ef4af2222f67bb10e26f096e7eab04dfc17 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 26 Jan 2015 17:48:28 +0100 Subject: [PATCH 2/2] Fix webdav put for single file webdav shares --- lib/private/connector/sabre/file.php | 6 +++--- tests/lib/connector/sabre/file.php | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index 0f5a3315f8..12ce633838 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 6bb1b4e75d..33dc78f87d 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 */