Fix renaming of shared files if target already exists, bug fix for oc-81
This commit is contained in:
parent
2e826fa82a
commit
d4636f4b86
|
@ -78,7 +78,9 @@ class OC_Share {
|
||||||
// Check if the target already exists for the user, if it does append a number to the name
|
// Check if the target already exists for the user, if it does append a number to the name
|
||||||
$sharedFolder = '/'.$uid.'/files/Shared';
|
$sharedFolder = '/'.$uid.'/files/Shared';
|
||||||
$target = $sharedFolder."/".basename($source);
|
$target = $sharedFolder."/".basename($source);
|
||||||
if (self::getSource($target)) {
|
$checkTarget = OCP\DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with ".self::getUsersAndGroups($uid, false)." LIMIT 1");
|
||||||
|
$result = $checkTarget->execute(array($target))->fetchAll();
|
||||||
|
if (count($result) > 0) {
|
||||||
if ($pos = strrpos($target, ".")) {
|
if ($pos = strrpos($target, ".")) {
|
||||||
$name = substr($target, 0, $pos);
|
$name = substr($target, 0, $pos);
|
||||||
$ext = substr($target, $pos);
|
$ext = substr($target, $pos);
|
||||||
|
@ -87,12 +89,11 @@ class OC_Share {
|
||||||
$ext = "";
|
$ext = "";
|
||||||
}
|
}
|
||||||
$counter = 1;
|
$counter = 1;
|
||||||
while ($checkTarget !== false) {
|
while (count($result) > 0) {
|
||||||
$newTarget = $name."_".$counter.$ext;
|
$target = $name."_".$counter.$ext;
|
||||||
$checkTarget = self::getSource($newTarget);
|
$result = $checkTarget->execute(array($target))->fetchAll();
|
||||||
$counter++;
|
$counter++;
|
||||||
}
|
}
|
||||||
$target = $newTarget;
|
|
||||||
}
|
}
|
||||||
if (isset($gid)) {
|
if (isset($gid)) {
|
||||||
$uid = $uid."@".$gid;
|
$uid = $uid."@".$gid;
|
||||||
|
|
Loading…
Reference in New Issue