aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib/sharedmount.php
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-05-22 01:41:27 +0200
committerRobin Appelman <icewind@owncloud.com>2014-06-06 09:55:59 +0200
commit14ce44acc8c44ebf669c46496c6b17524b3e2a4e (patch)
treef7d6c92889403702d72fc1f3030e22f580da8c2c /apps/files_sharing/lib/sharedmount.php
parentcabe2873c47004798eadd39d9f1ad811e7227137 (diff)
downloadnextcloud-server-14ce44acc8c44ebf669c46496c6b17524b3e2a4e.tar.gz
nextcloud-server-14ce44acc8c44ebf669c46496c6b17524b3e2a4e.zip
Move shared mount moving from the storage to the mount
Diffstat (limited to 'apps/files_sharing/lib/sharedmount.php')
-rw-r--r--apps/files_sharing/lib/sharedmount.php113
1 files changed, 113 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/sharedmount.php b/apps/files_sharing/lib/sharedmount.php
new file mode 100644
index 00000000000..f761f1b7bae
--- /dev/null
+++ b/apps/files_sharing/lib/sharedmount.php
@@ -0,0 +1,113 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCA\Files_Sharing;
+
+use OC\Files\Filesystem;
+use OC\Files\Mount\Mount;
+use OC\Files\Mount\MoveableMount;
+use OC\Files\Storage\Shared;
+
+/**
+ * Person mount points can be moved by the user
+ */
+class SharedMount extends Mount implements MoveableMount {
+ /**
+ * @var \OC\Files\Storage\Shared $storage
+ */
+ protected $storage = null;
+
+ /**
+ * 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'
+ */
+ private 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') {
+ \OCP\Util::writeLog('file sharing',
+ 'Can not strip userid and "files/" from path: ' . $path,
+ \OCP\Util::DEBUG);
+ return false;
+ }
+
+ // skip 'user' and 'files'
+ $sliced = array_slice($split, 2);
+ $relPath = implode('/', $sliced);
+
+ return '/' . $relPath;
+ }
+
+ /**
+ * Move the mount point to $target
+ *
+ * @param string $target the target mount point
+ * @return bool
+ */
+ public function moveMount($target) {
+ // it shouldn't be possible to move a Shared storage into another one
+ list($targetStorage,) = Filesystem::resolvePath($target);
+ if ($targetStorage instanceof Shared) {
+ \OCP\Util::writeLog('file sharing',
+ 'It is not allowed to move one mount point into another one',
+ \OCP\Util::DEBUG);
+ return false;
+ }
+
+ $relTargetPath = $this->stripUserFilesPath($target);
+ $share = $this->storage->getShare();
+
+ // if the user renames a mount point from a group share we need to create a new db entry
+ // for the unique name
+ if ($this->storage->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && $this->storage->uniqueNameSet() === false) {
+ $query = \OC_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, \OCP\User::getUser(), $share['uid_owner'], $share['permissions'], $share['stime'], $share['file_source'],
+ $relTargetPath, $share['token'], $share['id']);
+
+ } else {
+ // rename mount point
+ $query = \OC_DB::prepare(
+ 'UPDATE `*PREFIX*share`
+ SET `file_target` = ?
+ WHERE `id` = ?'
+ );
+ $arguments = array($relTargetPath, $this->storage->getShareId());
+ }
+
+ $result = $query->execute($arguments);
+
+ if ($result) {
+ $this->setMountPoint($target);
+ $this->storage->setUniqueName();
+ $this->storage->setMountPoint($relTargetPath);
+
+ } else {
+ \OCP\Util::writeLog('file sharing',
+ 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"',
+ \OCP\Util::ERROR);
+ }
+
+ return $result;
+ }
+
+ /**
+ * Remove the mount points
+ *
+ * @return mixed
+ * @return bool
+ */
+ public function removeMount() {
+ }
+}