From b712393e72fc22dc9d38f074b2eca848e6439bcf Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 14 Apr 2014 17:08:46 +0200 Subject: fix etag propagation --- apps/files_sharing/lib/helper.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'apps/files_sharing/lib/helper.php') diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php index b602fe3599d..1381c0002d3 100644 --- a/apps/files_sharing/lib/helper.php +++ b/apps/files_sharing/lib/helper.php @@ -111,4 +111,39 @@ class Helper { } return true; } + + public static function getSharesFromItem($target) { + $result = array(); + $owner = \OC\Files\Filesystem::getOwner($target); + \OC\Files\Filesystem::initMountPoints($owner); + $info = \OC\Files\Filesystem::getFileInfo($target); + $ownerView = new \OC\Files\View('/'.$owner.'/files'); + if ( $owner != \OCP\User::getUser() ) { + $path = $ownerView->getPath($info['fileid']); + } else { + $path = $target; + } + + + $ids = array(); + while ($path !== '' && $path !== '.' && $path !== '/') { + $info = $ownerView->getFileInfo($path); + $ids[] = $info['fileid']; + $path = dirname($path); + } + + if (!empty($ids)) { + + $idList = array_chunk($ids, 99, true); + + foreach ($idList as $subList) { + $statement = "SELECT `share_with`, `share_type`, `file_target` FROM `*PREFIX*share` WHERE `file_source` IN (" . implode(',', $subList) . ") AND `share_type` IN (0, 1, 2)"; + $query = \OCP\DB::prepare($statement); + $r = $query->execute(); + $result = array_merge($result, $r->fetchAll()); + } + } + + return $result; + } } -- cgit v1.2.3 From dd1e47b3b896e2ee59faf5f423bb911c5d2c2548 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 15 Apr 2014 20:26:04 +0200 Subject: typos, use, unused and return fixed --- apps/files_sharing/appinfo/update.php | 4 +++- apps/files_sharing/lib/helper.php | 7 +++---- apps/files_sharing/lib/sharedstorage.php | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) (limited to 'apps/files_sharing/lib/helper.php') diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php index ebeeae10d2c..c79a2291e92 100644 --- a/apps/files_sharing/appinfo/update.php +++ b/apps/files_sharing/appinfo/update.php @@ -18,7 +18,7 @@ if (version_compare($installedVersion, '0.4', '<')) { $users[] = $row['share_with']; $shares[$row['id']] = $row['file_target']; } else if ($row['share_type'] === "1" && ($row['item_type'] === 'file' || $row['item_type'] === 'folder')) { - //collect all group sharesX + //collect all group shares $users = array_merge($users, \OC_group::usersInGroup($row['share_with'])); $shares[$row['id']] = $row['file_target']; } else if ($row['share_type'] === "2") { @@ -48,7 +48,9 @@ if (version_compare($installedVersion, '0.4', '<')) { $statement .= ' END WHERE `id` IN (' . $ids . ')'; $query = OCP\DB::prepare($statement); + $query->execute(array()); + } } diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php index 1381c0002d3..e2780e98935 100644 --- a/apps/files_sharing/lib/helper.php +++ b/apps/files_sharing/lib/helper.php @@ -2,6 +2,9 @@ namespace OCA\Files_Sharing; +use OC_Config; +use PasswordHash; + class Helper { /** @@ -26,9 +29,6 @@ class Helper { exit; } - $type = $linkItem['item_type']; - $fileSource = $linkItem['file_source']; - $shareOwner = $linkItem['uid_owner']; $rootLinkItem = \OCP\Share::resolveReShare($linkItem); $path = null; if (isset($rootLinkItem['uid_owner'])) { @@ -61,7 +61,6 @@ class Helper { } $basePath = $path; - $rootName = basename($path); if ($relativePath !== null && \OC\Files\Filesystem::isReadable($basePath . $relativePath)) { $path .= \OC\Files\Filesystem::normalizePath($relativePath); diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index eedd279bf2b..b8a799f720d 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -299,14 +299,14 @@ class Shared extends \OC\Files\Storage\Common { } /** - * @brief rename a shared foder/file + * @brief rename a shared folder/file * @param string $sourcePath * @param string $targetPath * @return bool */ private function renameMountPoint($sourcePath, $targetPath) { - // it shoulbn't be possible to move a Shared storage into another one + // it shouldn't be possible to move a Shared storage into another one list($targetStorage, ) = \OC\Files\Filesystem::resolvePath($targetPath); if ($targetStorage instanceof \OC\Files\Storage\Shared) { \OCP\Util::writeLog('file sharing', @@ -452,6 +452,7 @@ class Shared extends \OC\Files\Storage\Common { list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source); return $storage->free_space($internalPath); } + return \OC\Files\SPACE_UNKNOWN; } public function getLocalFile($path) { -- cgit v1.2.3 From 93469ca46865d02d33710a2f70f7f6092c8f5c58 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 16 Apr 2014 16:41:23 +0200 Subject: make it possible to move files out of a shared mount point --- apps/files_sharing/lib/helper.php | 31 +++++++++++++++++++++++++++++++ apps/files_sharing/lib/sharedstorage.php | 27 ++++++++++++++------------- lib/private/files/view.php | 8 ++++---- 3 files changed, 49 insertions(+), 17 deletions(-) (limited to 'apps/files_sharing/lib/helper.php') diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php index e2780e98935..cc1f7d9ffdf 100644 --- a/apps/files_sharing/lib/helper.php +++ b/apps/files_sharing/lib/helper.php @@ -145,4 +145,35 @@ class Helper { return $result; } + + public static function getUidAndFilename($filename) { + $uid = \OC\Files\Filesystem::getOwner($filename); + \OC\Files\Filesystem::initMountPoints($uid); + if ( $uid != \OCP\User::getUser() ) { + $info = \OC\Files\Filesystem::getFileInfo($filename); + $ownerView = new \OC\Files\View('/'.$uid.'/files'); + $filename = $ownerView->getPath($info['fileid']); + } + return array($uid, $filename); + } + + /** + * @brief Format a path to be relative to the /user/files/ directory + * @param string $path the absolute path + * @return string e.g. turns '/admin/files/test.txt' into 'test.txt' + */ + public static function stripUserFilesPath($path) { + $trimmed = ltrim($path, '/'); + $split = explode('/', $trimmed); + + // it is not a file relative to data/user/files + if (count($split) < 3 || $split[1] !== 'files') { + return false; + } + + $sliced = array_slice($split, 2); + $relPath = implode('/', $sliced); + + return $relPath; + } } diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index b8a799f720d..5e478d5ead8 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -362,6 +362,9 @@ class Shared extends \OC\Files\Storage\Common { public function rename($path1, $path2) { $sourceMountPoint = \OC\Files\Filesystem::getMountPoint($path1); + $targetMountPoint = \OC\Files\Filesystem::getMountPoint($path2); + $relPath1 = \OCA\Files_Sharing\Helper::stripUserFilesPath($path1); + $relPath2 = \OCA\Files_Sharing\Helper::stripUserFilesPath($path2); // if we renamed the mount point we need to adjust the file_target in the // database @@ -369,21 +372,19 @@ class Shared extends \OC\Files\Storage\Common { return $this->renameMountPoint($path1, $path2); } - // Renaming/moving is only allowed within shared folders - $oldSource = $this->getSourcePath($path1); - if ($oldSource) { - $newSource = $this->getSourcePath(dirname($path2)) . '/' . basename($path2); - // Within the same folder, we only need UPDATE permissions - if (dirname($path1) == dirname($path2) and $this->isUpdatable($path1)) { - list($storage, $oldInternalPath) = \OC\Files\Filesystem::resolvePath($oldSource); - list(, $newInternalPath) = \OC\Files\Filesystem::resolvePath($newSource); - return $storage->rename($oldInternalPath, $newInternalPath); + + if ( // Within the same mount point, we only need UPDATE permissions + ($sourceMountPoint === $targetMountPoint && $this->isUpdatable($sourceMountPoint)) || // otherwise DELETE and CREATE permissions required - } elseif ($this->isDeletable($path1) && $this->isCreatable(dirname($path2))) { - $rootView = new \OC\Files\View(''); - return $rootView->rename($oldSource, $newSource); - } + ($this->isDeletable($path1) && $this->isCreatable(dirname($path2)))) { + + 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(''); + return $rootView->rename('/' . $user1 . '/files/' . $path1, '/' . $user2 . '/files/' . $path2 . '/' . $targetFilename); } + return false; } diff --git a/lib/private/files/view.php b/lib/private/files/view.php index a61d58aaf24..58dfc73dcf3 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -410,16 +410,16 @@ class View { // if source and target are on the same storage we can call the rename operation from the // storage. If it is a "Shared" file/folder we call always the rename operation of the // shared storage to handle mount point renaming, etc correctly - if ($mp1 == $mp2) { + if ($storage1 instanceof \OC\Files\Storage\Shared) { if ($storage1) { - $result = $storage1->rename($internalPath1, $internalPath2); + $result = $storage1->rename($absolutePath1, $absolutePath2); \OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2); } else { $result = false; } - } elseif ($storage1 instanceof \OC\Files\Storage\Shared) { + } elseif ($mp1 == $mp2) { if ($storage1) { - $result = $storage1->rename($absolutePath1, $absolutePath2); + $result = $storage1->rename($internalPath1, $internalPath2); \OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2); } else { $result = false; -- cgit v1.2.3