summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2012-10-02 11:37:26 +0200
committerBjörn Schießle <schiessle@owncloud.com>2012-10-02 11:41:26 +0200
commitc6c0fcc7c896e8c95bea021e2c91ed6a07917389 (patch)
treeba80202e68a519d8385cc8011e11bef652aa438a
parent550813ce411daa5f3665f9e8a4cec111d04ff486 (diff)
downloadnextcloud-server-c6c0fcc7c896e8c95bea021e2c91ed6a07917389.tar.gz
nextcloud-server-c6c0fcc7c896e8c95bea021e2c91ed6a07917389.zip
We can't rely on the assumption that if the matching target is from the same owner that the share type will be different.
Files in different folders can have the same name. Therefore also a unique name has to be generated if the matching target it from the same user. Also for folders and files with the same name a unique target name has to be generated If matching target is from the same owner, use the same target. The share type will be different so this isn't the sa
-rw-r--r--lib/public/share.php40
1 files changed, 30 insertions, 10 deletions
diff --git a/lib/public/share.php b/lib/public/share.php
index 1039d6f0dbf..8b3e5581d7b 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -1002,8 +1002,22 @@ class Share {
}
}
// Check if target already exists
- $checkTarget = self::getItems($itemType, $target, $shareType, $shareWith);
- if (!empty($checkTarget)) {
+ $targetConflict = false;
+
+ if( $itemType == "file" or $itemType == "folder") {
+ $itemList1 = self::getItems("file", $target, $shareType, $shareWith);
+ $itemList2 = self::getItems("folder", $target, $shareType, $shareWith);
+ if ( !empty($itemList1) or !empty($itemList2)) {
+ $targetConflict = true;
+ }
+ } else {
+ $itemList = self::getItems($itemType, $target, $shareType, $shareWith);
+ if ( !empty($itemList) ) {
+ $targetConflict = true;
+ }
+ }
+
+ if ($targetConflict) {
foreach ($checkTarget as $item) {
// Skip item if it is the group parent row
if (isset($groupParent) && $item['id'] == $groupParent) {
@@ -1013,21 +1027,27 @@ class Share {
continue;
}
}
- // If matching target is from the same owner, use the same target. The share type will be different so this isn't the same share.
- if ($item['uid_owner'] == $uidOwner) {
- return $target;
- }
}
if (!isset($exclude)) {
$exclude = array();
}
// Find similar targets to improve backend's chances to generate a unqiue target
if ($userAndGroups) {
- $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` IN (?,?,?) AND `share_with` IN (\''.implode('\',\'', $userAndGroups).'\') AND `'.$column.'` LIKE ?');
- $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique, '%'.$target.'%'));
+ if ($column == 'file_target') {
+ $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` IN (\'file\', \'folder\') AND `share_type` IN (?,?,?) AND `share_with` IN (\''.implode('\',\'', $userAndGroups).'\')');
+ $result = $checkTargets->execute(array(self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique));
+ } else {
+ $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` IN (?,?,?) AND `share_with` IN (\''.implode('\',\'', $userAndGroups).'\')');
+ $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique));
+ }
} else {
- $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` = ? AND `share_with` = ? AND `'.$column.'` LIKE ?');
- $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_GROUP, $shareWith, '%'.$target.'%'));
+ if ($column == 'file_target') {
+ $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` IN (\'file\', \'folder\') AND `share_type` = ? AND `share_with` = ?');
+ $result = $checkTargets->execute(array(self::SHARE_TYPE_GROUP, $shareWith));
+ } else {
+ $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` = ? AND `share_with` = ?');
+ $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_GROUP, $shareWith));
+ }
}
while ($row = $result->fetchRow()) {
$exclude[] = $row[$column];