summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-05-08 22:35:01 +0200
committerVincent Petry <pvince81@owncloud.com>2014-05-08 22:35:01 +0200
commit6e7c274d2ea70f7af5035c890aa39ea5096f7fd1 (patch)
tree106fef88a2b23626843b08b95ad3eb9b95060d45
parent8ede209ea3ca4913f7d6d4447ff14439ab3cf1b7 (diff)
parent05dc694c5c113079306a351f16a422e514d4a1e8 (diff)
downloadnextcloud-server-6e7c274d2ea70f7af5035c890aa39ea5096f7fd1.tar.gz
nextcloud-server-6e7c274d2ea70f7af5035c890aa39ea5096f7fd1.zip
Merge pull request #8499 from owncloud/shareextstoragemountpointfix
Fix sharing of ext storage mount points
-rw-r--r--apps/files_sharing/lib/share/file.php10
-rw-r--r--apps/files_sharing/tests/api.php57
-rw-r--r--lib/private/files/cache/cache.php4
3 files changed, 65 insertions, 6 deletions
diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php
index 2c59bd3bf92..9950b4d61fd 100644
--- a/apps/files_sharing/lib/share/file.php
+++ b/apps/files_sharing/lib/share/file.php
@@ -33,10 +33,12 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
private $path;
public function isValidSource($itemSource, $uidOwner) {
- $query = \OC_DB::prepare('SELECT `name` FROM `*PREFIX*filecache` WHERE `fileid` = ?');
- $result = $query->execute(array($itemSource));
- if ($row = $result->fetchRow()) {
- $this->path = $row['name'];
+ $path = \OC\Files\Filesystem::getPath($itemSource);
+ if ($path) {
+ // FIXME: attributes should not be set here,
+ // keeping this pattern for now to avoid unexpected
+ // regressions
+ $this->path = basename($path);
return true;
}
return false;
diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php
index b2f05d10ac6..2193717f4b4 100644
--- a/apps/files_sharing/tests/api.php
+++ b/apps/files_sharing/tests/api.php
@@ -29,10 +29,14 @@ use OCA\Files\Share;
*/
class Test_Files_Sharing_Api extends Test_Files_Sharing_Base {
+ const TEST_FOLDER_NAME = '/folder_share_api_test';
+
+ private static $tempStorage;
+
function setUp() {
parent::setUp();
- $this->folder = '/folder_share_api_test';
+ $this->folder = self::TEST_FOLDER_NAME;
$this->subfolder = '/subfolder_share_api_test';
$this->subsubfolder = '/subsubfolder_share_api_test';
@@ -51,6 +55,8 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base {
$this->view->unlink($this->filename);
$this->view->deleteAll($this->folder);
+ self::$tempStorage = null;
+
parent::tearDown();
}
@@ -929,6 +935,54 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base {
}
/**
+ * Post init mount points hook for mounting simulated ext storage
+ */
+ public static function initTestMountPointsHook($data) {
+ if ($data['user'] === \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1) {
+ \OC\Files\Filesystem::mount(self::$tempStorage, array(), '/' . \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1 . '/files' . self::TEST_FOLDER_NAME);
+ }
+ }
+
+ /**
+ * Tests mounting a folder that is an external storage mount point.
+ */
+ public function testShareStorageMountPoint() {
+ self::$tempStorage = new \OC\Files\Storage\Temporary(array());
+ self::$tempStorage->file_put_contents('test.txt', 'abcdef');
+ self::$tempStorage->getScanner()->scan('');
+
+ // needed because the sharing code sometimes switches the user internally and mounts the user's
+ // storages. In our case the temp storage isn't mounted automatically, so doing it in the post hook
+ // (similar to how ext storage works)
+ OCP\Util::connectHook('OC_Filesystem', 'post_initMountPoints', '\Test_Files_Sharing_Api', 'initTestMountPointsHook');
+
+ // logging in will auto-mount the temp storage for user1 as well
+ \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
+
+ $fileInfo = $this->view->getFileInfo($this->folder);
+
+ // user 1 shares the mount point folder with user2
+ $result = \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
+
+ $this->assertTrue($result);
+
+ // user2: check that mount point name appears correctly
+ \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
+
+ $view = new \OC\Files\View('/' . \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2 . '/files');
+
+ $this->assertTrue($view->file_exists($this->folder));
+ $this->assertTrue($view->file_exists($this->folder . '/test.txt'));
+
+ \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
+
+ \OCP\Share::unshare('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
+
+ \OC_Hook::clear('OC_Filesystem', 'post_initMountPoints', '\Test_Files_Sharing_Api', 'initTestMountPointsHook');
+ }
+ /**
* @expectedException \Exception
*/
public function testShareNonExisting() {
@@ -950,5 +1004,4 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base {
\OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_LINK, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
}
-
}
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php
index 1c9de56f8c5..c4f03b4d9ef 100644
--- a/lib/private/files/cache/cache.php
+++ b/lib/private/files/cache/cache.php
@@ -603,6 +603,10 @@ class Cache {
$sql = 'SELECT `path` FROM `*PREFIX*filecache` WHERE `fileid` = ? AND `storage` = ?';
$result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
if ($row = $result->fetchRow()) {
+ // Oracle stores empty strings as null...
+ if ($row['path'] === null) {
+ return '';
+ }
return $row['path'];
} else {
return null;