summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2014-05-27 20:48:41 +0200
committerRobin Appelman <icewind@owncloud.com>2014-06-06 09:56:00 +0200
commit5132ae5e69fa0d02c05f789fcda4609f291b638f (patch)
treefbddc15c130ddc790c057ac9f4edfb61db49ad2f /apps
parentb0a74edbb2fe91a8f82bb7437ff1a9ca4c3a03ec (diff)
downloadnextcloud-server-5132ae5e69fa0d02c05f789fcda4609f291b638f.tar.gz
nextcloud-server-5132ae5e69fa0d02c05f789fcda4609f291b638f.zip
fix mount point move up if the parent no longer exists
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/lib/sharedmount.php82
-rw-r--r--apps/files_sharing/lib/sharedstorage.php59
2 files changed, 61 insertions, 80 deletions
diff --git a/apps/files_sharing/lib/sharedmount.php b/apps/files_sharing/lib/sharedmount.php
index f1704504f64..873740f4a2d 100644
--- a/apps/files_sharing/lib/sharedmount.php
+++ b/apps/files_sharing/lib/sharedmount.php
@@ -22,6 +22,66 @@ class SharedMount extends Mount implements MoveableMount {
*/
protected $storage = null;
+ public function __construct($storage, $mountpoint, $arguments = null, $loader = null) {
+ parent::__construct($storage, $mountpoint, $arguments, $loader);
+
+ self::verifyMountPoint($arguments['share']);
+ }
+
+ /**
+ * check if the parent folder exists otherwise move the mount point up
+ */
+ private static function verifyMountPoint(&$share) {
+
+ $mountPoint = basename($share['file_target']);
+ $parent = dirname($share['file_target']);
+
+ while (!\OC\Files\Filesystem::is_dir($parent)) {
+ $parent = dirname($parent);
+ }
+
+ $newMountPoint = \OCA\Files_Sharing\Helper::generateUniqueTarget(
+ \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint),
+ array(),
+ new \OC\Files\View('/' . \OCP\User::getUser() . '/files')
+ );
+
+ if($newMountPoint !== $share['file_target']) {
+ self::updateFileTarget($newMountPoint, $share);
+ $share['file_target'] = $newMountPoint;
+ $share['unique_name'] = true;
+ }
+ }
+
+ /**
+ * 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 type
+ */
+ private static 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 && $this->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'],
+ $newPath, $share['token'], $share['id']);
+ } else {
+ // rename mount point
+ $query = \OC_DB::prepare(
+ 'Update `*PREFIX*share`
+ SET `file_target` = ?
+ WHERE `id` = ?'
+ );
+ $arguments = array($newPath, $share['id']);
+ }
+
+ return $query->execute($arguments);
+ }
+
/**
* Format a path to be relative to the /user/files/ directory
*
@@ -66,27 +126,7 @@ class SharedMount extends Mount implements MoveableMount {
$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);
+ $result = $this->updateFileTarget($relTargetPath, $share);
if ($result) {
$this->setMountPoint($target);
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index f8c241425d3..1456ad18888 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -401,7 +401,6 @@ class Shared extends \OC\Files\Storage\Common {
|| $shares
) {
foreach ($shares as $share) {
- self::verifyMountPoint($share);
$mount = new SharedMount(
'\OC\Files\Storage\Shared',
$options['user_dir'] . '/' . $share['file_target'],
@@ -416,64 +415,6 @@ class Shared extends \OC\Files\Storage\Common {
}
/**
- * check if the parent folder exists otherwise move the mount point up
- *
- * @param array $share reference to the share we want to check
- */
- private static function verifyMountPoint(&$share) {
- $mountPoint = basename($share['file_target']);
- $parent = dirname($share['file_target']);
-
- while (!\OC\Files\Filesystem::is_dir($parent)) {
- $parent = dirname($parent);
- }
-
- $newMountPoint = \OCA\Files_Sharing\Helper::generateUniqueTarget(
- \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint),
- array(),
- new \OC\Files\View('/' . \OCP\User::getUser() . '/files')
- );
-
- if($newMountPoint !== $share['file_target']) {
-
- self::updateFileTarget($newMountPoint, $share);
- $share['file_target'] = $newMountPoint;
-
- }
- }
-
- /**
- * 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 type
- */
- private static 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 && $this->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'],
- $newPath, $share['token'], $share['id']);
-
- $this->setUniqueName();
- } else {
- // rename mount point
- $query = \OC_DB::prepare(
- 'Update `*PREFIX*share`
- SET `file_target` = ?
- WHERE `id` = ?'
- );
- $arguments = array($newPath, $share['id']);
- }
-
- return $query->execute($arguments);
- }
-
- /**
* return mount point of share, relative to data/user/files
*
* @return string