]> source.dussan.org Git - nextcloud-server.git/commitdiff
Implement generateTarget for file sharing backend
authorMichael Gapczynski <mtgap@owncloud.com>
Sat, 1 Sep 2012 17:46:57 +0000 (13:46 -0400)
committerMichael Gapczynski <mtgap@owncloud.com>
Sat, 1 Sep 2012 17:46:57 +0000 (13:46 -0400)
apps/files_sharing/lib/share/file.php

index b1e3ca8b48ca8429b79b7e9b66c5c92572af6049..82744924be30a2e3003843df7fe4c44db20a850d 100644 (file)
@@ -46,9 +46,25 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
                return false;
        }
 
-       public function generateTarget($itemSource, $shareWith, $exclude = null) {
-               // TODO Make sure target path doesn't exist already
-               return $itemSource;
+       public function generateTarget($filePath, $shareWith, $exclude = null) {
+               $target = $filePath;
+               if (isset($exclude)) {
+                       if ($pos = strrpos($target, '.')) {
+                               $name = substr($target, 0, $pos);
+                               $ext = substr($target, $pos);
+                       } else {
+                               $name = $filePath;
+                               $ext = '';
+                       }
+                       $i = 2;
+                       $append = '';
+                       while (in_array($name.$append.$ext, $exclude)) {
+                               $append = ' ('.$i.')';
+                               $i++;
+                       }
+                       $target = $name.$append.$ext;
+               }
+               return $target;
        }
 
        public function formatItems($items, $format, $parameters = null) {