diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-05-26 12:37:43 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-05-26 14:11:33 +0200 |
commit | 95bd7fee9c0cb77e5ad89c13aaa836240933ef37 (patch) | |
tree | f1d0dff09738fd3fb8915281fda572ea6756a185 /apps | |
parent | 790c0e8e7ccc44fc859cfa5b97ef2d8aa1df87d7 (diff) | |
download | nextcloud-server-95bd7fee9c0cb77e5ad89c13aaa836240933ef37.tar.gz nextcloud-server-95bd7fee9c0cb77e5ad89c13aaa836240933ef37.zip |
don't lose file size during rename
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/lib/sharedstorage.php | 10 | ||||
-rw-r--r-- | apps/files_sharing/tests/sharedstorage.php | 46 |
2 files changed, 46 insertions, 10 deletions
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 02a8ebab93a..67ccbd13403 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -177,13 +177,9 @@ class Shared extends \OC\Files\Storage\Common { } public function filesize($path) { - if ($path == '' || $path == '/' || $this->is_dir($path)) { - return 0; - } else if ($source = $this->getSourcePath($path)) { - list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source); - return $storage->filesize($internalPath); - } - return false; + $source = $this->getSourcePath($path); + list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source); + return $storage->filesize($internalPath); } public function isCreatable($path) { diff --git a/apps/files_sharing/tests/sharedstorage.php b/apps/files_sharing/tests/sharedstorage.php index 258a2a9841b..b80ab6b4f14 100644 --- a/apps/files_sharing/tests/sharedstorage.php +++ b/apps/files_sharing/tests/sharedstorage.php @@ -36,12 +36,17 @@ class Test_Files_Sharing_Storage extends Test_Files_Sharing_Base { $this->filename = '/share-api-storage.txt'; - // save file with content + $this->view->mkdir($this->folder); + + // save file with content + $this->view->file_put_contents($this->filename, "root file"); + $this->view->file_put_contents($this->folder . $this->filename, "file in subfolder"); } function tearDown() { - $this->view->deleteAll($this->folder); + $this->view->unlink($this->folder); + $this->view->unlink($this->filename); parent::tearDown(); } @@ -123,7 +128,42 @@ class Test_Files_Sharing_Storage extends Test_Files_Sharing_Base { $this->assertTrue($this->view->file_exists( $this->folder. '/foo.txt')); //cleanup - $this->view->unlink($this->folder); + \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, + self::TEST_FILES_SHARING_API_USER2); + } + + public function testFilesize() { + + $fileinfoFolder = $this->view->getFileInfo($this->folder); + $fileinfoFile = $this->view->getFileInfo($this->filename); + + $folderSize = $this->view->filesize($this->folder); + $file1Size = $this->view->filesize($this->folder. $this->filename); + $file2Size = $this->view->filesize($this->filename); + + $result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, + self::TEST_FILES_SHARING_API_USER2, 31); + $this->assertTrue($result); + + $result = \OCP\Share::shareItem('file', $fileinfoFile['fileid'], \OCP\Share::SHARE_TYPE_USER, + self::TEST_FILES_SHARING_API_USER2, 31); + $this->assertTrue($result); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER2); + + // compare file size between user1 and user2, should always be the same + $this->assertSame($folderSize, \OC\Files\Filesystem::filesize($this->folder)); + $this->assertSame($file1Size, \OC\Files\Filesystem::filesize($this->folder . $this->filename)); + $this->assertSame($file2Size, \OC\Files\Filesystem::filesize($this->filename)); + + //cleanup + self::loginHelper(self::TEST_FILES_SHARING_API_USER1); + $result = \OCP\Share::unshare('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, + self::TEST_FILES_SHARING_API_USER2); + $this->assertTrue($result); + $result = \OCP\Share::unshare('file', $fileinfoFile['fileid'], \OCP\Share::SHARE_TYPE_USER, + self::TEST_FILES_SHARING_API_USER2); + $this->assertTrue($result); } } |