Move SharedStorage et al over to the shareManager and jail
This commit is contained in:
parent
3f95d44ed1
commit
6123badbfa
|
@ -111,7 +111,8 @@ class Application extends App {
|
||||||
/** @var \OCP\IServerContainer $server */
|
/** @var \OCP\IServerContainer $server */
|
||||||
$server = $c->query('ServerContainer');
|
$server = $c->query('ServerContainer');
|
||||||
return new MountProvider(
|
return new MountProvider(
|
||||||
$server->getConfig()
|
$server->getConfig(),
|
||||||
|
$server->getShareManager()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -102,4 +102,8 @@ class Shared_Cache extends CacheJail {
|
||||||
public function clear() {
|
public function clear() {
|
||||||
// Not a valid action for Shared Cache
|
// Not a valid action for Shared Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
|
||||||
|
parent::moveFromCache($sourceCache, $sourcePath, $this->storage->getSourcePath($targetPath));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,11 @@
|
||||||
|
|
||||||
namespace OCA\Files_Sharing;
|
namespace OCA\Files_Sharing;
|
||||||
|
|
||||||
use OC\Files\Filesystem;
|
|
||||||
use OC\User\NoUserException;
|
|
||||||
use OCP\Files\Config\IMountProvider;
|
use OCP\Files\Config\IMountProvider;
|
||||||
use OCP\Files\Storage\IStorageFactory;
|
use OCP\Files\Storage\IStorageFactory;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
|
use OCP\Share\IManager;
|
||||||
|
|
||||||
class MountProvider implements IMountProvider {
|
class MountProvider implements IMountProvider {
|
||||||
/**
|
/**
|
||||||
|
@ -36,10 +35,17 @@ class MountProvider implements IMountProvider {
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \OCP\IConfig $config
|
* @var IManager
|
||||||
*/
|
*/
|
||||||
public function __construct(IConfig $config) {
|
protected $shareManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \OCP\IConfig $config
|
||||||
|
* @param IManager $shareManager
|
||||||
|
*/
|
||||||
|
public function __construct(IConfig $config, IManager $shareManager) {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
$this->shareManager = $shareManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,18 +57,21 @@ class MountProvider implements IMountProvider {
|
||||||
* @return \OCP\Files\Mount\IMountPoint[]
|
* @return \OCP\Files\Mount\IMountPoint[]
|
||||||
*/
|
*/
|
||||||
public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) {
|
public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) {
|
||||||
$shares = \OCP\Share::getItemsSharedWithUser('file', $user->getUID());
|
$shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1);
|
||||||
$shares = array_filter($shares, function ($share) {
|
$shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1));
|
||||||
return $share['permissions'] > 0;
|
$shares = array_filter($shares, function (\OCP\Share\IShare $share) {
|
||||||
|
return $share->getPermissions() > 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
$mounts = [];
|
$mounts = [];
|
||||||
foreach ($shares as $share) {
|
foreach ($shares as $share) {
|
||||||
|
|
||||||
$mounts[] = new SharedMount(
|
$mounts[] = new SharedMount(
|
||||||
'\OC\Files\Storage\Shared',
|
'\OC\Files\Storage\Shared',
|
||||||
$mounts,
|
$mounts,
|
||||||
[
|
[
|
||||||
'share' => $share,
|
'user' => $user->getUID(),
|
||||||
'user' => $user->getUID()
|
'newShare' => $share,
|
||||||
],
|
],
|
||||||
$storageFactory
|
$storageFactory
|
||||||
);
|
);
|
||||||
|
|
|
@ -42,7 +42,10 @@ class SharedScanner extends Scanner {
|
||||||
*/
|
*/
|
||||||
public function getData($path) {
|
public function getData($path) {
|
||||||
$data = parent::getData($path);
|
$data = parent::getData($path);
|
||||||
$sourcePath = $this->storage->getSourcePath($path);
|
if ($data === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$sourcePath = '/' . $this->storage->getOwner($path) . '/' . $this->storage->getSourcePath($path);
|
||||||
list($sourceStorage, $internalPath) = \OC\Files\Filesystem::resolvePath($sourcePath);
|
list($sourceStorage, $internalPath) = \OC\Files\Filesystem::resolvePath($sourcePath);
|
||||||
$data['permissions'] = $sourceStorage->getPermissions($internalPath);
|
$data['permissions'] = $sourceStorage->getPermissions($internalPath);
|
||||||
return $data;
|
return $data;
|
||||||
|
|
|
@ -58,23 +58,25 @@ class SharedMount extends MountPoint implements MoveableMount {
|
||||||
public function __construct($storage, array $mountpoints, $arguments = null, $loader = null) {
|
public function __construct($storage, array $mountpoints, $arguments = null, $loader = null) {
|
||||||
$this->user = $arguments['user'];
|
$this->user = $arguments['user'];
|
||||||
$this->recipientView = new View('/' . $this->user . '/files');
|
$this->recipientView = new View('/' . $this->user . '/files');
|
||||||
$newMountPoint = $this->verifyMountPoint($arguments['share'], $mountpoints);
|
/** @var \OCP\Share\IShare $share */
|
||||||
|
$share = $arguments['newShare'];
|
||||||
|
$newMountPoint = $this->verifyMountPoint($share, $mountpoints);
|
||||||
$absMountPoint = '/' . $this->user . '/files' . $newMountPoint;
|
$absMountPoint = '/' . $this->user . '/files' . $newMountPoint;
|
||||||
$arguments['ownerView'] = new View('/' . $arguments['share']['uid_owner'] . '/files');
|
$arguments['ownerView'] = new View('/' . $share->getShareOwner() . '/files');
|
||||||
parent::__construct($storage, $absMountPoint, $arguments, $loader);
|
parent::__construct($storage, $absMountPoint, $arguments, $loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the parent folder exists otherwise move the mount point up
|
* check if the parent folder exists otherwise move the mount point up
|
||||||
*
|
*
|
||||||
* @param array $share
|
* @param \OCP\Share\IShare $share
|
||||||
* @param SharedMount[] $mountpoints
|
* @param SharedMount[] $mountpoints
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function verifyMountPoint(&$share, array $mountpoints) {
|
private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints) {
|
||||||
|
|
||||||
$mountPoint = basename($share['file_target']);
|
$mountPoint = basename($share->getTarget());
|
||||||
$parent = dirname($share['file_target']);
|
$parent = dirname($share->getTarget());
|
||||||
|
|
||||||
if (!$this->recipientView->is_dir($parent)) {
|
if (!$this->recipientView->is_dir($parent)) {
|
||||||
$parent = Helper::getShareFolder();
|
$parent = Helper::getShareFolder();
|
||||||
|
@ -86,15 +88,26 @@ class SharedMount extends MountPoint implements MoveableMount {
|
||||||
$mountpoints
|
$mountpoints
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($newMountPoint !== $share['file_target']) {
|
if ($newMountPoint !== $share->getTarget()) {
|
||||||
$this->updateFileTarget($newMountPoint, $share);
|
$this->updateFileTarget($newMountPoint, $share);
|
||||||
$share['file_target'] = $newMountPoint;
|
|
||||||
$share['unique_name'] = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $newMountPoint;
|
return $newMountPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update fileTarget in the database if the mount point changed
|
||||||
|
*
|
||||||
|
* @param string $newPath
|
||||||
|
* @param \OCP\Share\IShare $share
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function updateFileTarget($newPath, &$share) {
|
||||||
|
$share->setTarget($newPath);
|
||||||
|
\OC::$server->getShareManager()->moveShare($share, $this->user);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param View $view
|
* @param View $view
|
||||||
|
@ -110,7 +123,7 @@ class SharedMount extends MountPoint implements MoveableMount {
|
||||||
// Helper function to find existing mount points
|
// Helper function to find existing mount points
|
||||||
$mountpointExists = function($path) use ($mountpoints) {
|
$mountpointExists = function($path) use ($mountpoints) {
|
||||||
foreach ($mountpoints as $mountpoint) {
|
foreach ($mountpoints as $mountpoint) {
|
||||||
if ($mountpoint->getShare()['file_target'] === $path) {
|
if ($mountpoint->getShare()->getTarget() === $path) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,38 +139,6 @@ class SharedMount extends MountPoint implements MoveableMount {
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* update fileTarget in the database if the mount point changed
|
|
||||||
*
|
|
||||||
* @param string $newPath
|
|
||||||
* @param array $share reference to the share which should be modified
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function updateFileTarget($newPath, &$share) {
|
|
||||||
// if the user renames a mount point from a group share we need to create a new db entry
|
|
||||||
// for the unique name
|
|
||||||
if ($share['share_type'] === \OCP\Share::SHARE_TYPE_GROUP && empty($share['unique_name'])) {
|
|
||||||
$query = \OCP\DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`, `item_target`,'
|
|
||||||
.' `share_type`, `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`,'
|
|
||||||
.' `file_target`, `token`, `parent`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)');
|
|
||||||
$arguments = array($share['item_type'], $share['item_source'], $share['item_target'],
|
|
||||||
2, $this->user, $share['uid_owner'], $share['permissions'], $share['stime'], $share['file_source'],
|
|
||||||
$newPath, $share['token'], $share['id']);
|
|
||||||
} else {
|
|
||||||
// rename mount point
|
|
||||||
$query = \OCP\DB::prepare(
|
|
||||||
'Update `*PREFIX*share`
|
|
||||||
SET `file_target` = ?
|
|
||||||
WHERE `id` = ?'
|
|
||||||
);
|
|
||||||
$arguments = array($newPath, $share['id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $query->execute($arguments);
|
|
||||||
|
|
||||||
return $result === 1 ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format a path to be relative to the /user/files/ directory
|
* Format a path to be relative to the /user/files/ directory
|
||||||
*
|
*
|
||||||
|
@ -197,20 +178,11 @@ class SharedMount extends MountPoint implements MoveableMount {
|
||||||
|
|
||||||
$result = true;
|
$result = true;
|
||||||
|
|
||||||
if (!empty($share['grouped'])) {
|
try {
|
||||||
foreach ($share['grouped'] as $s) {
|
$this->updateFileTarget($relTargetPath, $share);
|
||||||
$result = $this->updateFileTarget($relTargetPath, $s) && $result;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$result = $this->updateFileTarget($relTargetPath, $share) && $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($result) {
|
|
||||||
$this->setMountPoint($target);
|
$this->setMountPoint($target);
|
||||||
$this->storage->setUniqueName();
|
|
||||||
$this->storage->setMountPoint($relTargetPath);
|
$this->storage->setMountPoint($relTargetPath);
|
||||||
|
} catch (\Exception $e) {
|
||||||
} else {
|
|
||||||
\OCP\Util::writeLog('file sharing',
|
\OCP\Util::writeLog('file sharing',
|
||||||
'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"',
|
'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"',
|
||||||
\OCP\Util::ERROR);
|
\OCP\Util::ERROR);
|
||||||
|
@ -235,7 +207,7 @@ class SharedMount extends MountPoint implements MoveableMount {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return \OCP\Share\IShare
|
||||||
*/
|
*/
|
||||||
public function getShare() {
|
public function getShare() {
|
||||||
/** @var $storage \OC\Files\Storage\Shared */
|
/** @var $storage \OC\Files\Storage\Shared */
|
||||||
|
|
|
@ -36,9 +36,8 @@ class SharedPropagator extends Propagator {
|
||||||
* @return \array[] all propagated entries
|
* @return \array[] all propagated entries
|
||||||
*/
|
*/
|
||||||
public function propagateChange($internalPath, $time, $sizeDifference = 0) {
|
public function propagateChange($internalPath, $time, $sizeDifference = 0) {
|
||||||
$source = $this->storage->getSourcePath($internalPath);
|
|
||||||
/** @var \OC\Files\Storage\Storage $storage */
|
/** @var \OC\Files\Storage\Storage $storage */
|
||||||
list($storage, $sourceInternalPath) = \OC\Files\Filesystem::resolvePath($source);
|
list($storage, $sourceInternalPath) = $this->storage->resolvePath($internalPath);
|
||||||
return $storage->getPropagator()->propagateChange($sourceInternalPath, $time, $sizeDifference);
|
return $storage->getPropagator()->propagateChange($sourceInternalPath, $time, $sizeDifference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,21 +41,18 @@ use OCP\Lock\ILockingProvider;
|
||||||
/**
|
/**
|
||||||
* Convert target path to source path and pass the function call to the correct storage provider
|
* Convert target path to source path and pass the function call to the correct storage provider
|
||||||
*/
|
*/
|
||||||
class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage {
|
||||||
|
|
||||||
private $share; // the shared resource
|
private $share; // the shared resource
|
||||||
private $files = array();
|
|
||||||
|
/** @var \OCP\Share\IShare */
|
||||||
|
private $newShare;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\Files\View
|
* @var \OC\Files\View
|
||||||
*/
|
*/
|
||||||
private $ownerView;
|
private $ownerView;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $user;
|
|
||||||
|
|
||||||
private $initialized = false;
|
private $initialized = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,16 +65,28 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
*/
|
*/
|
||||||
private $sourceStorage;
|
private $sourceStorage;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
private $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OCP\ILogger
|
* @var \OCP\ILogger
|
||||||
*/
|
*/
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
public function __construct($arguments) {
|
public function __construct($arguments) {
|
||||||
$this->share = $arguments['share'];
|
|
||||||
$this->ownerView = $arguments['ownerView'];
|
$this->ownerView = $arguments['ownerView'];
|
||||||
$this->user = $arguments['user'];
|
|
||||||
$this->logger = \OC::$server->getLogger();
|
$this->logger = \OC::$server->getLogger();
|
||||||
|
$this->newShare = $arguments['newShare'];
|
||||||
|
$this->user = $arguments['user'];
|
||||||
|
|
||||||
|
Filesystem::initMountPoints($this->newShare->getShareOwner());
|
||||||
|
$sourcePath = $this->ownerView->getPath($this->newShare->getNodeId());
|
||||||
|
list($storage, $internalPath) = $this->ownerView->resolvePath($sourcePath);
|
||||||
|
|
||||||
|
parent::__construct([
|
||||||
|
'storage' => $storage,
|
||||||
|
'root' => $internalPath,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function init() {
|
private function init() {
|
||||||
|
@ -86,8 +95,8 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
}
|
}
|
||||||
$this->initialized = true;
|
$this->initialized = true;
|
||||||
try {
|
try {
|
||||||
Filesystem::initMountPoints($this->share['uid_owner']);
|
Filesystem::initMountPoints($this->newShare->getShareOwner());
|
||||||
$sourcePath = $this->ownerView->getPath($this->share['file_source']);
|
$sourcePath = $this->ownerView->getPath($this->newShare->getNodeId());
|
||||||
list($this->sourceStorage, $sourceInternalPath) = $this->ownerView->resolvePath($sourcePath);
|
list($this->sourceStorage, $sourceInternalPath) = $this->ownerView->resolvePath($sourcePath);
|
||||||
$this->sourceRootInfo = $this->sourceStorage->getCache()->get($sourceInternalPath);
|
$this->sourceRootInfo = $this->sourceStorage->getCache()->get($sourceInternalPath);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -115,59 +124,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getSourceId() {
|
public function getSourceId() {
|
||||||
return (int)$this->share['file_source'];
|
return $this->newShare->getNodeId();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the source file path, permissions, and owner for a shared file
|
|
||||||
*
|
|
||||||
* @param string $target Shared target file path
|
|
||||||
* @return array Returns array with the keys path, permissions, and owner or false if not found
|
|
||||||
*/
|
|
||||||
public function getFile($target) {
|
|
||||||
$this->init();
|
|
||||||
if (!isset($this->files[$target])) {
|
|
||||||
// Check for partial files
|
|
||||||
if (pathinfo($target, PATHINFO_EXTENSION) === 'part') {
|
|
||||||
$source = \OC_Share_Backend_File::getSource(substr($target, 0, -5), $this->getShare());
|
|
||||||
if ($source) {
|
|
||||||
$source['path'] .= '.part';
|
|
||||||
// All partial files have delete permission
|
|
||||||
$source['permissions'] |= \OCP\Constants::PERMISSION_DELETE;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$source = \OC_Share_Backend_File::getSource($target, $this->getShare());
|
|
||||||
}
|
|
||||||
$this->files[$target] = $source;
|
|
||||||
}
|
|
||||||
return $this->files[$target];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the source file path for a shared file
|
|
||||||
*
|
|
||||||
* @param string $target Shared target file path
|
|
||||||
* @return string|false source file path or false if not found
|
|
||||||
*/
|
|
||||||
public function getSourcePath($target) {
|
|
||||||
if (!$this->isValid()){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$source = $this->getFile($target);
|
|
||||||
if ($source) {
|
|
||||||
if (!isset($source['fullPath'])) {
|
|
||||||
\OC\Files\Filesystem::initMountPoints($source['fileOwner']);
|
|
||||||
$mount = \OC\Files\Filesystem::getMountByNumericId($source['storage']);
|
|
||||||
if (is_array($mount) && !empty($mount)) {
|
|
||||||
$this->files[$target]['fullPath'] = $mount[key($mount)]->getMountPoint() . $source['path'];
|
|
||||||
} else {
|
|
||||||
$this->files[$target]['fullPath'] = false;
|
|
||||||
\OCP\Util::writeLog('files_sharing', "Unable to get mount for shared storage '" . $source['storage'] . "' user '" . $source['fileOwner'] . "'", \OCP\Util::ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->files[$target]['fullPath'];
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -180,7 +137,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
if (!$this->isValid()) {
|
if (!$this->isValid()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
$permissions = $this->share['permissions'];
|
$permissions = $this->newShare->getPermissions();
|
||||||
// part files and the mount point always have delete permissions
|
// part files and the mount point always have delete permissions
|
||||||
if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') {
|
if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') {
|
||||||
$permissions |= \OCP\Constants::PERMISSION_DELETE;
|
$permissions |= \OCP\Constants::PERMISSION_DELETE;
|
||||||
|
@ -193,84 +150,6 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
return $permissions;
|
return $permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function mkdir($path) {
|
|
||||||
if ($path == '' || $path == '/' || !$this->isCreatable(dirname($path))) {
|
|
||||||
return false;
|
|
||||||
} else if ($source = $this->getSourcePath($path)) {
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->mkdir($internalPath);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete the directory if DELETE permission is granted
|
|
||||||
*
|
|
||||||
* @param string $path
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function rmdir($path) {
|
|
||||||
|
|
||||||
// never delete a share mount point
|
|
||||||
if (empty($path)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) {
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->rmdir($internalPath);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function opendir($path) {
|
|
||||||
$source = $this->getSourcePath($path);
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->opendir($internalPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function is_dir($path) {
|
|
||||||
$source = $this->getSourcePath($path);
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->is_dir($internalPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function is_file($path) {
|
|
||||||
if ($source = $this->getSourcePath($path)) {
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->is_file($internalPath);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stat($path) {
|
|
||||||
if ($path == '' || $path == '/') {
|
|
||||||
$stat['size'] = $this->filesize($path);
|
|
||||||
$stat['mtime'] = $this->filemtime($path);
|
|
||||||
return $stat;
|
|
||||||
} else if ($source = $this->getSourcePath($path)) {
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->stat($internalPath);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function filetype($path) {
|
|
||||||
if ($path == '' || $path == '/') {
|
|
||||||
return 'dir';
|
|
||||||
} else if ($source = $this->getSourcePath($path)) {
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->filetype($internalPath);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function filesize($path) {
|
|
||||||
$source = $this->getSourcePath($path);
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->filesize($internalPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isCreatable($path) {
|
public function isCreatable($path) {
|
||||||
return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE);
|
return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE);
|
||||||
}
|
}
|
||||||
|
@ -301,127 +180,6 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE);
|
return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function file_exists($path) {
|
|
||||||
if ($path == '' || $path == '/') {
|
|
||||||
return true;
|
|
||||||
} else if ($source = $this->getSourcePath($path)) {
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->file_exists($internalPath);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function filemtime($path) {
|
|
||||||
$source = $this->getSourcePath($path);
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->filemtime($internalPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function file_get_contents($path) {
|
|
||||||
$source = $this->getSourcePath($path);
|
|
||||||
if ($source) {
|
|
||||||
$info = array(
|
|
||||||
'target' => $this->getMountPoint() . $path,
|
|
||||||
'source' => $source,
|
|
||||||
);
|
|
||||||
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->file_get_contents($internalPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function file_put_contents($path, $data) {
|
|
||||||
if ($source = $this->getSourcePath($path)) {
|
|
||||||
// Check if permission is granted
|
|
||||||
if (($this->file_exists($path) && !$this->isUpdatable($path))
|
|
||||||
|| ($this->is_dir($path) && !$this->isCreatable($path))
|
|
||||||
) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$info = array(
|
|
||||||
'target' => $this->getMountPoint() . '/' . $path,
|
|
||||||
'source' => $source,
|
|
||||||
);
|
|
||||||
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
$result = $storage->file_put_contents($internalPath, $data);
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete the file if DELETE permission is granted
|
|
||||||
*
|
|
||||||
* @param string $path
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function unlink($path) {
|
|
||||||
|
|
||||||
// never delete a share mount point
|
|
||||||
if (empty($path)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($source = $this->getSourcePath($path)) {
|
|
||||||
if ($this->isDeletable($path)) {
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->unlink($internalPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function rename($path1, $path2) {
|
|
||||||
$this->init();
|
|
||||||
// we need the paths relative to data/user/files
|
|
||||||
$relPath1 = $this->getMountPoint() . '/' . $path1;
|
|
||||||
$relPath2 = $this->getMountPoint() . '/' . $path2;
|
|
||||||
$pathinfo = pathinfo($relPath1);
|
|
||||||
|
|
||||||
$isPartFile = (isset($pathinfo['extension']) && $pathinfo['extension'] === 'part');
|
|
||||||
$targetExists = $this->file_exists($path2);
|
|
||||||
$sameFolder = (dirname($relPath1) === dirname($relPath2));
|
|
||||||
if ($targetExists || ($sameFolder && !$isPartFile)) {
|
|
||||||
// note that renaming a share mount point is always allowed
|
|
||||||
if (!$this->isUpdatable('')) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!$this->isCreatable('')) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \OC\Files\Storage\Storage $sourceStorage
|
|
||||||
*/
|
|
||||||
list($sourceStorage, $sourceInternalPath) = $this->resolvePath($path1);
|
|
||||||
/**
|
|
||||||
* @var \OC\Files\Storage\Storage $targetStorage
|
|
||||||
*/
|
|
||||||
list($targetStorage, $targetInternalPath) = $this->resolvePath($path2);
|
|
||||||
|
|
||||||
return $targetStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function copy($path1, $path2) {
|
|
||||||
// Copy the file if CREATE permission is granted
|
|
||||||
if ($this->isCreatable(dirname($path2))) {
|
|
||||||
/**
|
|
||||||
* @var \OC\Files\Storage\Storage $sourceStorage
|
|
||||||
*/
|
|
||||||
list($sourceStorage, $sourceInternalPath) = $this->resolvePath($path1);
|
|
||||||
/**
|
|
||||||
* @var \OC\Files\Storage\Storage $targetStorage
|
|
||||||
*/
|
|
||||||
list($targetStorage, $targetInternalPath) = $this->resolvePath($path2);
|
|
||||||
|
|
||||||
return $targetStorage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fopen($path, $mode) {
|
public function fopen($path, $mode) {
|
||||||
if ($source = $this->getSourcePath($path)) {
|
if ($source = $this->getSourcePath($path)) {
|
||||||
switch ($mode) {
|
switch ($mode) {
|
||||||
|
@ -465,43 +223,34 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
'mode' => $mode,
|
'mode' => $mode,
|
||||||
);
|
);
|
||||||
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info);
|
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info);
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
return parent::fopen($path, $mode);
|
||||||
return $storage->fopen($internalPath, $mode);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMimeType($path) {
|
/**
|
||||||
if ($source = $this->getSourcePath($path)) {
|
* see http://php.net/manual/en/function.rename.php
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
*
|
||||||
return $storage->getMimeType($internalPath);
|
* @param string $path1
|
||||||
}
|
* @param string $path2
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function rename($path1, $path2) {
|
||||||
|
$isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part';
|
||||||
|
$targetExists = $this->file_exists($path2);
|
||||||
|
$sameFodler = dirname($path1) === dirname($path2);
|
||||||
|
|
||||||
|
if ($targetExists || ($sameFodler && !$isPartFile)) {
|
||||||
|
if (!$this->isUpdatable('')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
public function free_space($path) {
|
if (!$this->isCreatable('')) {
|
||||||
$source = $this->getSourcePath($path);
|
|
||||||
if ($source) {
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->free_space($internalPath);
|
|
||||||
}
|
|
||||||
return \OCP\Files\FileInfo::SPACE_UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLocalFile($path) {
|
|
||||||
if ($source = $this->getSourcePath($path)) {
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->getLocalFile($internalPath);
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function touch($path, $mtime = null) {
|
|
||||||
if ($source = $this->getSourcePath($path)) {
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->touch($internalPath, $mtime);
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
return parent::rename($path1, $path2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -510,33 +259,21 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getMountPoint() {
|
public function getMountPoint() {
|
||||||
return $this->share['file_target'];
|
return $this->newShare->getTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $path
|
||||||
|
*/
|
||||||
public function setMountPoint($path) {
|
public function setMountPoint($path) {
|
||||||
$this->share['file_target'] = $path;
|
$this->newShare->setTarget($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
public function getShareType() {
|
public function getShareType() {
|
||||||
return $this->share['share_type'];
|
return $this->newShare->getShareType();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* does the group share already has a user specific unique name
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function uniqueNameSet() {
|
|
||||||
return (isset($this->share['unique_name']) && $this->share['unique_name']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the share now uses a unique name of this user
|
|
||||||
*
|
|
||||||
* @brief the share now uses a unique name of this user
|
|
||||||
*/
|
|
||||||
public function setUniqueName() {
|
|
||||||
$this->share['unique_name'] = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -545,7 +282,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
* @return integer unique share ID
|
* @return integer unique share ID
|
||||||
*/
|
*/
|
||||||
public function getShareId() {
|
public function getShareId() {
|
||||||
return $this->share['id'];
|
return $this->newShare->getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -554,14 +291,14 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getSharedFrom() {
|
public function getSharedFrom() {
|
||||||
return $this->share['uid_owner'];
|
return $this->newShare->getShareOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return \OCP\Share\IShare
|
||||||
*/
|
*/
|
||||||
public function getShare() {
|
public function getShare() {
|
||||||
return $this->share;
|
return $this->newShare;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -570,11 +307,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getItemType() {
|
public function getItemType() {
|
||||||
return $this->share['item_type'];
|
return $this->newShare->getNodeType();
|
||||||
}
|
|
||||||
|
|
||||||
public function hasUpdated($path, $time) {
|
|
||||||
return $this->filemtime($path) > $time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCache($path = '', $storage = null) {
|
public function getCache($path = '', $storage = null) {
|
||||||
|
@ -603,22 +336,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOwner($path) {
|
public function getOwner($path) {
|
||||||
if ($path == '') {
|
return $this->newShare->getShareOwner();
|
||||||
$path = $this->getMountPoint();
|
|
||||||
}
|
|
||||||
$source = $this->getFile($path);
|
|
||||||
if ($source) {
|
|
||||||
return $source['fileOwner'];
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getETag($path) {
|
|
||||||
if ($source = $this->getSourcePath($path)) {
|
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
|
||||||
return $storage->getETag($internalPath);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -627,15 +345,8 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function unshareStorage() {
|
public function unshareStorage() {
|
||||||
$result = true;
|
\OC::$server->getShareManager()->deleteFromSelf($this->newShare, $this->user);
|
||||||
if (!empty($this->share['grouped'])) {
|
return true;
|
||||||
foreach ($this->share['grouped'] as $share) {
|
|
||||||
$result = $result && \OCP\Share::unshareFromSelf($share['item_type'], $share['file_target']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$result = $result && \OCP\Share::unshareFromSelf($this->getItemType(), $this->getMountPoint());
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -645,34 +356,10 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function resolvePath($path) {
|
public function resolvePath($path) {
|
||||||
$source = $this->getSourcePath($path);
|
$source = '/' . $this->newShare->getShareOwner() . '/' . $this->getSourcePath($path);
|
||||||
return \OC\Files\Filesystem::resolvePath($source);
|
return \OC\Files\Filesystem::resolvePath($source);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \OCP\Files\Storage $sourceStorage
|
|
||||||
* @param string $sourceInternalPath
|
|
||||||
* @param string $targetInternalPath
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
|
|
||||||
/** @var \OCP\Files\Storage $targetStorage */
|
|
||||||
list($targetStorage, $targetInternalPath) = $this->resolvePath($targetInternalPath);
|
|
||||||
return $targetStorage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \OCP\Files\Storage $sourceStorage
|
|
||||||
* @param string $sourceInternalPath
|
|
||||||
* @param string $targetInternalPath
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
|
|
||||||
/** @var \OCP\Files\Storage $targetStorage */
|
|
||||||
list($targetStorage, $targetInternalPath) = $this->resolvePath($targetInternalPath);
|
|
||||||
return $targetStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
|
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
|
||||||
|
@ -685,7 +372,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
$targetStorage->acquireLock($targetInternalPath, $type, $provider);
|
$targetStorage->acquireLock($targetInternalPath, $type, $provider);
|
||||||
// lock the parent folders of the owner when locking the share as recipient
|
// lock the parent folders of the owner when locking the share as recipient
|
||||||
if ($path === '') {
|
if ($path === '') {
|
||||||
$sourcePath = $this->ownerView->getPath($this->share['file_source']);
|
$sourcePath = $this->ownerView->getPath($this->newShare->getNodeId());
|
||||||
$this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
|
$this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -701,7 +388,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
$targetStorage->releaseLock($targetInternalPath, $type, $provider);
|
$targetStorage->releaseLock($targetInternalPath, $type, $provider);
|
||||||
// unlock the parent folders of the owner when unlocking the share as recipient
|
// unlock the parent folders of the owner when unlocking the share as recipient
|
||||||
if ($path === '') {
|
if ($path === '') {
|
||||||
$sourcePath = $this->ownerView->getPath($this->share['file_source']);
|
$sourcePath = $this->ownerView->getPath($this->newShare->getNodeId());
|
||||||
$this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
|
$this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -735,14 +422,28 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
// shares do not participate in availability logic
|
// shares do not participate in availability logic
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isLocal() {
|
|
||||||
$this->init();
|
|
||||||
$ownerPath = $this->ownerView->getPath($this->share['item_source']);
|
|
||||||
list($targetStorage) = $this->ownerView->resolvePath($ownerPath);
|
|
||||||
return $targetStorage->isLocal();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSourceStorage() {
|
public function getSourceStorage() {
|
||||||
return $this->sourceStorage;
|
return $this->sourceStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \OCP\Files\Storage $sourceStorage
|
||||||
|
* @param string $sourceInternalPath
|
||||||
|
* @param string $targetInternalPath
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
|
||||||
|
return parent::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) {
|
||||||
|
return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $this->getSourcePath($targetInternalPath));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,10 @@ class Shared_Updater {
|
||||||
|
|
||||||
$src = $userFolder->get($path);
|
$src = $userFolder->get($path);
|
||||||
|
|
||||||
$type = $src instanceof \OCP\Files\File ? 'file' : 'folder';
|
$shareManager = \OC::$server->getShareManager();
|
||||||
$shares = \OCP\Share::getItemShared($type, $src->getId());
|
|
||||||
|
$shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_USER, $src, false, -1);
|
||||||
|
$shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $src, false, -1));
|
||||||
|
|
||||||
// If the path we move is not a share we don't care
|
// If the path we move is not a share we don't care
|
||||||
if (empty($shares)) {
|
if (empty($shares)) {
|
||||||
|
@ -96,14 +98,13 @@ class Shared_Updater {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$parenShare = $dstMount->getShare();
|
$newOwner = $dstMount->getShare()->getShareOwner();
|
||||||
|
|
||||||
|
//Ownership is moved over
|
||||||
foreach ($shares as $share) {
|
foreach ($shares as $share) {
|
||||||
$qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
|
/** @var \OCP\Share\IShare $share */
|
||||||
$qb->update('share')
|
$share->setShareOwner($newOwner);
|
||||||
->set('parent', $qb->createNamedParameter($parenShare['id']))
|
$shareManager->updateShare($share);
|
||||||
->where($qb->expr()->eq('id', $qb->createNamedParameter($share['id'])))
|
|
||||||
->execute();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue