]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix renaming of shared files if target already exists, bug fix for oc-81
authorMichael Gapczynski <GapczynskiM@gmail.com>
Wed, 9 May 2012 21:01:46 +0000 (17:01 -0400)
committerMichael Gapczynski <GapczynskiM@gmail.com>
Wed, 9 May 2012 21:01:46 +0000 (17:01 -0400)
apps/files_sharing/lib_share.php

index ecf82abb31e35c3bf33f7c66ec542a9c47104081..3bcc2b562e5280079b2d9e1ecd6f1df6ec034a02 100755 (executable)
@@ -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
                                $sharedFolder = '/'.$uid.'/files/Shared';
                                $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, ".")) {
                                                $name = substr($target, 0, $pos);
                                                $ext = substr($target, $pos);
@@ -87,12 +89,11 @@ class OC_Share {
                                                $ext = "";
                                        }
                                        $counter = 1;
-                                       while ($checkTarget !== false) {
-                                               $newTarget = $name."_".$counter.$ext;
-                                               $checkTarget = self::getSource($newTarget);
+                                       while (count($result) > 0) {
+                                               $target = $name."_".$counter.$ext;
+                                               $result = $checkTarget->execute(array($target))->fetchAll();
                                                $counter++;
                                        }
-                                       $target = $newTarget;
                                }
                                if (isset($gid)) {
                                        $uid = $uid."@".$gid;