diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-06-29 19:13:39 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2015-07-01 15:10:22 +0200 |
commit | d6f56ea609c41431458c0b565042caf945ab56cc (patch) | |
tree | 9c892e68d5b1d50e9ec6b9611089e32f996b0b63 /apps/files_sharing/lib | |
parent | 5caeda33f155145a74f6108326deb13314eedff2 (diff) | |
download | nextcloud-server-d6f56ea609c41431458c0b565042caf945ab56cc.tar.gz nextcloud-server-d6f56ea609c41431458c0b565042caf945ab56cc.zip |
lock parent folders for the owner when locking a shared file as recipient
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r-- | apps/files_sharing/lib/sharedmount.php | 27 | ||||
-rw-r--r-- | apps/files_sharing/lib/sharedstorage.php | 16 |
2 files changed, 33 insertions, 10 deletions
diff --git a/apps/files_sharing/lib/sharedmount.php b/apps/files_sharing/lib/sharedmount.php index 2afc0f1f270..fd672d0500c 100644 --- a/apps/files_sharing/lib/sharedmount.php +++ b/apps/files_sharing/lib/sharedmount.php @@ -41,34 +41,40 @@ class SharedMount extends MountPoint implements MoveableMount { */ protected $ownerPropagator; + /** + * @var \OC\Files\View + */ + private $recipientView; + public function __construct($storage, $mountpoint, $arguments = null, $loader = null) { // first update the mount point before creating the parent $this->ownerPropagator = $arguments['propagator']; - $newMountPoint = $this->verifyMountPoint($arguments['share'], $arguments['user']); + $this->recipientView = new View('/' . $arguments['user'] . '/files'); + $newMountPoint = $this->verifyMountPoint($arguments['share']); $absMountPoint = '/' . $arguments['user'] . '/files' . $newMountPoint; + $arguments['ownerView'] = new View('/' . $arguments['share']['uid_owner'] . '/files'); parent::__construct($storage, $absMountPoint, $arguments, $loader); } /** * check if the parent folder exists otherwise move the mount point up */ - private function verifyMountPoint(&$share, $user) { + private function verifyMountPoint(&$share) { $mountPoint = basename($share['file_target']); $parent = dirname($share['file_target']); - $view = new View('/' . $user . '/files'); - if (!$view->is_dir($parent)) { + if (!$this->recipientView->is_dir($parent)) { $parent = Helper::getShareFolder(); } $newMountPoint = \OCA\Files_Sharing\Helper::generateUniqueTarget( - \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), - array(), - new \OC\Files\View('/' . $user . '/files') - ); + \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), + [], + $this->recipientView + ); - if($newMountPoint !== $share['file_target']) { + if ($newMountPoint !== $share['file_target']) { self::updateFileTarget($newMountPoint, $share); $share['file_target'] = $newMountPoint; $share['unique_name'] = true; @@ -79,6 +85,7 @@ class SharedMount extends MountPoint implements MoveableMount { /** * 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 @@ -99,7 +106,7 @@ class SharedMount extends MountPoint implements MoveableMount { 'Update `*PREFIX*share` SET `file_target` = ? WHERE `id` = ?' - ); + ); $arguments = array($newPath, $share['id']); } diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 50957663b34..e54f747d3ba 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -45,8 +45,14 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage { private $files = array(); private static $isInitialized = array(); + /** + * @var \OC\Files\View + */ + private $ownerView; + public function __construct($arguments) { $this->share = $arguments['share']; + $this->ownerView = $arguments['ownerView']; } /** @@ -623,6 +629,11 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage { /** @var \OCP\Files\Storage $targetStorage */ list($targetStorage, $targetInternalPath) = $this->resolvePath($path); $targetStorage->acquireLock($targetInternalPath, $type, $provider); + // lock the parent folders of the owner when locking the share as recipient + if ($path === '') { + $sourcePath = $this->ownerView->getPath($this->share['file_source']); + $this->ownerView->lockFile($sourcePath, ILockingProvider::LOCK_SHARED, true); + } } /** @@ -634,6 +645,11 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage { /** @var \OCP\Files\Storage $targetStorage */ list($targetStorage, $targetInternalPath) = $this->resolvePath($path); $targetStorage->releaseLock($targetInternalPath, $type, $provider); + // unlock the parent folders of the owner when unlocking the share as recipient + if ($path === '') { + $sourcePath = $this->ownerView->getPath($this->share['file_source']); + $this->ownerView->unlockFile($sourcePath, ILockingProvider::LOCK_SHARED, true); + } } /** |