summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2014-04-30 17:52:29 +0200
committerLukas Reschke <lukas@statuscode.ch>2014-04-30 17:52:29 +0200
commit9ee88104e96250a3e8c0d648b5bf2369ab051a64 (patch)
tree88bf532fab40aa08264ae723c9f8d09a18a4c169
parent11404b2b12a47b519ce6b3d0606ced8ad2649769 (diff)
parent20e4ad382b69d728c3044b2b96ef51413d5a4e8f (diff)
downloadnextcloud-server-9ee88104e96250a3e8c0d648b5bf2369ab051a64.tar.gz
nextcloud-server-9ee88104e96250a3e8c0d648b5bf2369ab051a64.zip
Merge pull request #8412 from owncloud/sharing_fix_part_file_rename
[sharing] fix rename of part files
-rw-r--r--apps/files_encryption/lib/proxy.php14
-rw-r--r--apps/files_sharing/lib/sharedstorage.php10
-rw-r--r--apps/files_sharing/tests/sharedstorage.php83
3 files changed, 98 insertions, 9 deletions
diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index 03ddc795eae..7be82c313e4 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -340,26 +340,24 @@ class Proxy extends \OC_FileProxy {
$fileInfo['unencrypted_size'] = $fixSize;
// put file info if not .part file
if (!Helper::isPartialFilePath($relativePath)) {
- $view->putFileInfo($path, $fileInfo);
+ $view->putFileInfo($path, array('unencrypted_size' => $fixSize));
}
}
$size = $fileInfo['unencrypted_size'];
} else {
- // self healing if file was removed from file cache
- if (!$fileInfo) {
- $fileInfo = array();
- }
+
+ $fileInfoUpdates = array();
$fixSize = $util->getFileSize($path);
if ($fixSize > 0) {
$size = $fixSize;
- $fileInfo['encrypted'] = true;
- $fileInfo['unencrypted_size'] = $size;
+ $fileInfoUpdates['encrypted'] = true;
+ $fileInfoUpdates['unencrypted_size'] = $size;
// put file info if not .part file
if (!Helper::isPartialFilePath($relativePath)) {
- $view->putFileInfo($path, $fileInfo);
+ $view->putFileInfo($path, $fileInfoUpdates);
}
}
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index 2252ec6a1a6..4733dff3d14 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -379,7 +379,15 @@ class Shared extends \OC\Files\Storage\Common {
// otherwise DELETE and CREATE permissions required
($this->isDeletable($path1) && $this->isCreatable(dirname($path2)))) {
- list($user1, $path1) = \OCA\Files_Sharing\Helper::getUidAndFilename($relPath1);
+ $pathinfo = pathinfo($relPath1);
+ // for part files we need to ask for the owner and path from the parent directory because
+ // the file cache doesn't return any results for part files
+ if ($pathinfo['extension'] === 'part') {
+ list($user1, $path1) = \OCA\Files_Sharing\Helper::getUidAndFilename($pathinfo['dirname']);
+ $path1 = $path1 . '/' . $pathinfo['basename'];
+ } else {
+ list($user1, $path1) = \OCA\Files_Sharing\Helper::getUidAndFilename($relPath1);
+ }
$targetFilename = basename($relPath2);
list($user2, $path2) = \OCA\Files_Sharing\Helper::getUidAndFilename(dirname($relPath2));
$rootView = new \OC\Files\View('');
diff --git a/apps/files_sharing/tests/sharedstorage.php b/apps/files_sharing/tests/sharedstorage.php
new file mode 100644
index 00000000000..66518a2633f
--- /dev/null
+++ b/apps/files_sharing/tests/sharedstorage.php
@@ -0,0 +1,83 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Bjoern Schiessle
+ * @copyright 2014 Bjoern Schiessle <schiessle@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+require_once __DIR__ . '/base.php';
+
+use OCA\Files\Share;
+
+/**
+ * Class Test_Files_Sharing_Api
+ */
+class Test_Files_Sharing_Storage extends Test_Files_Sharing_Base {
+
+ function setUp() {
+ parent::setUp();
+
+ $this->folder = '/folder_share_storage_test';
+
+ $this->filename = '/share-api-storage.txt';
+
+ // save file with content
+ $this->view->mkdir($this->folder);
+ }
+
+ function tearDown() {
+ $this->view->deleteAll($this->folder);
+
+ parent::tearDown();
+ }
+
+ /**
+ * @medium
+ */
+ function testRenamePartFile() {
+
+ // share to user
+ $fileinfo = $this->view->getFileInfo($this->folder);
+ $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ self::TEST_FILES_SHARING_API_USER2, 31);
+
+ $this->assertTrue($result);
+
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
+ $user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
+
+ $this->assertTrue($user2View->file_exists($this->folder));
+
+ // create part file
+ $result = $user2View->file_put_contents($this->folder. '/foo.txt.part', 'some test data');
+
+ $this->assertTrue(is_int($result));
+ // rename part file to real file
+ $result = $user2View->rename($this->folder. '/foo.txt.part', $this->folder. '/foo.txt');
+
+ $this->assertTrue($result);
+
+ // check if the new file really exists
+ $this->assertTrue($user2View->file_exists( $this->folder. '/foo.txt'));
+
+ // check if the rename also affected the owner
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
+
+ $this->assertTrue($this->view->file_exists( $this->folder. '/foo.txt'));
+ }
+}