summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <DeepDiver1975@users.noreply.github.com>2016-04-20 20:37:27 +0200
committerThomas Müller <DeepDiver1975@users.noreply.github.com>2016-04-20 20:37:27 +0200
commitcd01c440a01744d666df275cb7941fa29d2283dd (patch)
treed09caccace60dcfcc42e9b00ae2d810ec29643cc /lib
parentcdcabbd0b3f6209b2a312b30a84c381f125bcf68 (diff)
parentb53d6598f10c97318fbf065369f5b097eb134e28 (diff)
downloadnextcloud-server-cd01c440a01744d666df275cb7941fa29d2283dd.tar.gz
nextcloud-server-cd01c440a01744d666df275cb7941fa29d2283dd.zip
Merge pull request #23919 from owncloud/cyclyc-share-dep-example
SharedStorage to new sharing code + cleanup
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Share20/Manager.php51
-rw-r--r--lib/private/files/cache/wrapper/cachejail.php16
-rw-r--r--lib/private/files/config/cachedmountinfo.php14
-rw-r--r--lib/private/files/config/lazystoragemountinfo.php74
-rw-r--r--lib/private/files/config/usermountcache.php11
-rw-r--r--lib/private/files/mount/mountpoint.php9
-rw-r--r--lib/private/files/storage/common.php24
-rw-r--r--lib/private/files/storage/wrapper/jail.php46
-rw-r--r--lib/private/files/storage/wrapper/wrapper.php6
-rw-r--r--lib/private/helper.php2
-rw-r--r--lib/public/files/mount/imountpoint.php8
11 files changed, 211 insertions, 50 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 1ec25750cfe..dee9e0cdd21 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -237,6 +237,17 @@ class Manager implements IManager {
if (($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) {
throw new \InvalidArgumentException('Shares need at least read permissions');
}
+
+ if ($share->getNode() instanceof \OCP\Files\File) {
+ if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) {
+ $message_t = $this->l->t('Files can\'t be shared with delete permissions');
+ throw new GenericShareException($message_t);
+ }
+ if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) {
+ $message_t = $this->l->t('Files can\'t be shared with create permissions');
+ throw new GenericShareException($message_t);
+ }
+ }
}
/**
@@ -505,6 +516,24 @@ class Manager implements IManager {
$this->generalCreateChecks($share);
+ // Verify if there are any issues with the path
+ $this->pathCreateChecks($share->getNode());
+
+ /*
+ * On creation of a share the owner is always the owner of the path
+ * Except for mounted federated shares.
+ */
+ $storage = $share->getNode()->getStorage();
+ if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
+ $parent = $share->getNode()->getParent();
+ while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
+ $parent = $parent->getParent();
+ }
+ $share->setShareOwner($parent->getOwner()->getUID());
+ } else {
+ $share->setShareOwner($share->getNode()->getOwner()->getUID());
+ }
+
//Verify share type
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
$this->userCreateChecks($share);
@@ -538,24 +567,6 @@ class Manager implements IManager {
}
}
- // Verify if there are any issues with the path
- $this->pathCreateChecks($share->getNode());
-
- /*
- * On creation of a share the owner is always the owner of the path
- * Except for mounted federated shares.
- */
- $storage = $share->getNode()->getStorage();
- if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
- $parent = $share->getNode()->getParent();
- while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
- $parent = $parent->getParent();
- }
- $share->setShareOwner($parent->getOwner()->getUID());
- } else {
- $share->setShareOwner($share->getNode()->getOwner()->getUID());
- }
-
// Cannot share with the owner
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
$share->getSharedWith() === $share->getShareOwner()) {
@@ -818,7 +829,7 @@ class Manager implements IManager {
* @param string $recipientId
*/
public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) {
- list($providerId, ) = $this->splitFullId($share->getId());
+ list($providerId, ) = $this->splitFullId($share->getFullId());
$provider = $this->factory->getProvider($providerId);
$provider->deleteFromSelf($share, $recipientId);
@@ -844,7 +855,7 @@ class Manager implements IManager {
}
}
- list($providerId, ) = $this->splitFullId($share->getId());
+ list($providerId, ) = $this->splitFullId($share->getFullId());
$provider = $this->factory->getProvider($providerId);
$provider->move($share, $recipientId);
diff --git a/lib/private/files/cache/wrapper/cachejail.php b/lib/private/files/cache/wrapper/cachejail.php
index 868e63cdf81..88b0f23a1fc 100644
--- a/lib/private/files/cache/wrapper/cachejail.php
+++ b/lib/private/files/cache/wrapper/cachejail.php
@@ -281,4 +281,20 @@ class CacheJail extends CacheWrapper {
$path = $this->cache->getPathById($id);
return $this->getJailedPath($path);
}
+
+ /**
+ * Move a file or folder in the cache
+ *
+ * Note that this should make sure the entries are removed from the source cache
+ *
+ * @param \OCP\Files\Cache\ICache $sourceCache
+ * @param string $sourcePath
+ * @param string $targetPath
+ */
+ public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
+ if ($sourceCache === $this) {
+ return $this->move($sourcePath, $targetPath);
+ }
+ return $this->cache->moveFromCache($sourceCache, $sourcePath, $targetPath);
+ }
}
diff --git a/lib/private/files/config/cachedmountinfo.php b/lib/private/files/config/cachedmountinfo.php
index 2993c979a7f..ce75cb66896 100644
--- a/lib/private/files/config/cachedmountinfo.php
+++ b/lib/private/files/config/cachedmountinfo.php
@@ -30,22 +30,22 @@ class CachedMountInfo implements ICachedMountInfo {
/**
* @var IUser
*/
- private $user;
+ protected $user;
/**
* @var int
*/
- private $storageId;
+ protected $storageId;
/**
* @var int
*/
- private $rootId;
+ protected $rootId;
/**
* @var string
*/
- private $mountPoint;
+ protected $mountPoint;
/**
* CachedMountInfo constructor.
@@ -88,9 +88,9 @@ class CachedMountInfo implements ICachedMountInfo {
*/
public function getMountPointNode() {
// TODO injection etc
- Filesystem::initMountPoints($this->user->getUID());
- $userNode = \OC::$server->getUserFolder($this->user->getUID());
- $nodes = $userNode->getById($this->rootId);
+ Filesystem::initMountPoints($this->getUser()->getUID());
+ $userNode = \OC::$server->getUserFolder($this->getUser()->getUID());
+ $nodes = $userNode->getById($this->getRootId());
if (count($nodes) > 0) {
return $nodes[0];
} else {
diff --git a/lib/private/files/config/lazystoragemountinfo.php b/lib/private/files/config/lazystoragemountinfo.php
new file mode 100644
index 00000000000..654c5b2b23e
--- /dev/null
+++ b/lib/private/files/config/lazystoragemountinfo.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * @author Robin Appelman <icewind@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Files\Config;
+
+use OC\Files\Filesystem;
+use OCP\Files\Config\ICachedMountInfo;
+use OCP\Files\Mount\IMountPoint;
+use OCP\Files\Node;
+use OCP\IUser;
+
+class LazyStorageMountInfo extends CachedMountInfo {
+ /** @var IMountPoint */
+ private $mount;
+
+ /**
+ * CachedMountInfo constructor.
+ *
+ * @param IUser $user
+ * @param IMountPoint $mount
+ */
+ public function __construct(IUser $user, IMountPoint $mount) {
+ $this->user = $user;
+ $this->mount = $mount;
+ }
+
+ /**
+ * @return int the numeric storage id of the mount
+ */
+ public function getStorageId() {
+ if (!$this->storageId) {
+ $this->storageId = $this->mount->getStorage()->getStorageCache()->getNumericId();
+ }
+ return parent::getStorageId();
+ }
+
+ /**
+ * @return int the fileid of the root of the mount
+ */
+ public function getRootId() {
+ if (!$this->rootId) {
+ $this->rootId = $this->mount->getStorageRootId();
+ }
+ return parent::getRootId();
+ }
+
+ /**
+ * @return string the mount point of the mount for the user
+ */
+ public function getMountPoint() {
+ if (!$this->mountPoint) {
+ $this->mountPoint = $this->mount->getMountPoint();
+ }
+ return parent::getMountPoint();
+ }
+}
diff --git a/lib/private/files/config/usermountcache.php b/lib/private/files/config/usermountcache.php
index 78b19972787..05ca146f4be 100644
--- a/lib/private/files/config/usermountcache.php
+++ b/lib/private/files/config/usermountcache.php
@@ -80,18 +80,11 @@ class UserMountCache implements IUserMountCache {
});
/** @var ICachedMountInfo[] $newMounts */
$newMounts = array_map(function (IMountPoint $mount) use ($user) {
- $storage = $mount->getStorage();
- if ($storage->instanceOfStorage('\OC\Files\Storage\Shared')) {
- $rootId = (int)$storage->getShare()['file_source'];
- } else {
- $rootId = (int)$storage->getCache()->getId('');
- }
- $storageId = (int)$storage->getStorageCache()->getNumericId();
// filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet)
- if ($rootId === -1) {
+ if ($mount->getStorageRootId() === -1) {
return null;
} else {
- return new CachedMountInfo($user, $storageId, $rootId, $mount->getMountPoint());
+ return new LazyStorageMountInfo($user, $mount);
}
}, $mounts);
$newMounts = array_values(array_filter($newMounts));
diff --git a/lib/private/files/mount/mountpoint.php b/lib/private/files/mount/mountpoint.php
index b606c625cb1..7b9294fc1e0 100644
--- a/lib/private/files/mount/mountpoint.php
+++ b/lib/private/files/mount/mountpoint.php
@@ -239,4 +239,13 @@ class MountPoint implements IMountPoint {
public function getOptions() {
return $this->mountOptions;
}
+
+ /**
+ * Get the file id of the root of the storage
+ *
+ * @return int
+ */
+ public function getStorageRootId() {
+ return (int)$this->getStorage()->getCache()->getId('');
+ }
}
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index 85c2e1c6700..3a811b312c6 100644
--- a/lib/private/files/storage/common.php
+++ b/lib/private/files/storage/common.php
@@ -313,20 +313,20 @@ abstract class Common implements Storage, ILockingStorage {
if (!$storage) {
$storage = $this;
}
- if (!isset($this->cache)) {
- $this->cache = new Cache($storage);
+ if (!isset($storage->cache)) {
+ $storage->cache = new Cache($storage);
}
- return $this->cache;
+ return $storage->cache;
}
public function getScanner($path = '', $storage = null) {
if (!$storage) {
$storage = $this;
}
- if (!isset($this->scanner)) {
- $this->scanner = new Scanner($storage);
+ if (!isset($storage->scanner)) {
+ $storage->scanner = new Scanner($storage);
}
- return $this->scanner;
+ return $storage->scanner;
}
public function getWatcher($path = '', $storage = null) {
@@ -351,20 +351,20 @@ abstract class Common implements Storage, ILockingStorage {
if (!$storage) {
$storage = $this;
}
- if (!isset($this->propagator)) {
- $this->propagator = new Propagator($storage);
+ if (!isset($storage->propagator)) {
+ $storage->propagator = new Propagator($storage);
}
- return $this->propagator;
+ return $storage->propagator;
}
public function getUpdater($storage = null) {
if (!$storage) {
$storage = $this;
}
- if (!isset($this->updater)) {
- $this->updater = new Updater($storage);
+ if (!isset($storage->updater)) {
+ $storage->updater = new Updater($storage);
}
- return $this->updater;
+ return $storage->updater;
}
public function getStorageCache($storage = null) {
diff --git a/lib/private/files/storage/wrapper/jail.php b/lib/private/files/storage/wrapper/jail.php
index e5f5ab90359..e8063f670c5 100644
--- a/lib/private/files/storage/wrapper/jail.php
+++ b/lib/private/files/storage/wrapper/jail.php
@@ -47,7 +47,7 @@ class Jail extends Wrapper {
$this->rootPath = $arguments['root'];
}
- protected function getSourcePath($path) {
+ public function getSourcePath($path) {
if ($path === '') {
return $this->rootPath;
} else {
@@ -417,6 +417,14 @@ class Jail extends Wrapper {
/**
* @param string $path
+ * @return array
+ */
+ public function getMetaData($path) {
+ return $this->storage->getMetaData($this->getSourcePath($path));
+ }
+
+ /**
+ * @param string $path
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
* @param \OCP\Lock\ILockingProvider $provider
* @throws \OCP\Lock\LockedException
@@ -442,4 +450,40 @@ class Jail extends Wrapper {
public function changeLock($path, $type, ILockingProvider $provider) {
$this->storage->changeLock($this->getSourcePath($path), $type, $provider);
}
+
+ /**
+ * Resolve the path for the source of the share
+ *
+ * @param string $path
+ * @return array
+ */
+ public function resolvePath($path) {
+ return [$this->storage, $this->getSourcePath($path)];
+ }
+
+ /**
+ * @param \OCP\Files\Storage $sourceStorage
+ * @param string $sourceInternalPath
+ * @param string $targetInternalPath
+ * @return bool
+ */
+ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
+ if ($sourceStorage === $this) {
+ return $this->copy($sourceInternalPath, $targetInternalPath);
+ }
+ return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $this->getSourcePath($targetInternalPath));
+ }
+
+ /**
+ * @param \OCP\Files\Storage $sourceStorage
+ * @param string $sourceInternalPath
+ * @param string $targetInternalPath
+ * @return bool
+ */
+ public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
+ if ($sourceStorage === $this) {
+ return $this->rename($sourceInternalPath, $targetInternalPath);
+ }
+ return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $this->getSourcePath($targetInternalPath));
+ }
}
diff --git a/lib/private/files/storage/wrapper/wrapper.php b/lib/private/files/storage/wrapper/wrapper.php
index 12914e7a1b8..21d7db1099b 100644
--- a/lib/private/files/storage/wrapper/wrapper.php
+++ b/lib/private/files/storage/wrapper/wrapper.php
@@ -35,6 +35,12 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage {
*/
protected $storage;
+ public $cache;
+ public $scanner;
+ public $watcher;
+ public $propagator;
+ public $updater;
+
/**
* @param array $parameters
*/
diff --git a/lib/private/helper.php b/lib/private/helper.php
index 70c50bb7b4b..e6aaed0fd15 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -628,7 +628,7 @@ class OC_Helper {
/** @var \OC\Files\Storage\Wrapper\Quota $storage */
$quota = $sourceStorage->getQuota();
}
- $free = $storage->free_space('');
+ $free = $sourceStorage->free_space('');
if ($free >= 0) {
$total = $free + $used;
} else {
diff --git a/lib/public/files/mount/imountpoint.php b/lib/public/files/mount/imountpoint.php
index 9ce1396c1d1..bc7bf81709f 100644
--- a/lib/public/files/mount/imountpoint.php
+++ b/lib/public/files/mount/imountpoint.php
@@ -94,4 +94,12 @@ interface IMountPoint {
* @since 8.1.0
*/
public function getOptions();
+
+ /**
+ * Get the file id of the root of the storage
+ *
+ * @return int
+ * @since 9.1.0
+ */
+ public function getStorageRootId();
}