]> source.dussan.org Git - nextcloud-server.git/commitdiff
overwrite target on rename
authorJörn Friedrich Dreyer <jfd@butonic.de>
Tue, 16 Aug 2016 13:22:45 +0000 (15:22 +0200)
committerJörn Friedrich Dreyer <jfd@butonic.de>
Fri, 26 Aug 2016 07:38:01 +0000 (09:38 +0200)
apps/files_external/lib/smb.php

index c60f096c65704d3fc84386cd2e1fa5f2bd93355c..2a4ae53bcf4bd6e633d558373a9bd36717b067b2 100644 (file)
@@ -30,6 +30,7 @@
 
 namespace OC\Files\Storage;
 
+use Icewind\SMB\Exception\AlreadyExistsException;
 use Icewind\SMB\Exception\ConnectException;
 use Icewind\SMB\Exception\Exception;
 use Icewind\SMB\Exception\ForbiddenException;
@@ -188,6 +189,39 @@ class SMB extends Common {
                }
        }
 
+       /**
+        * Rename the files
+        *
+        * @param string $source the old name of the path
+        * @param string $target the new name of the path
+        * @return bool true if the rename is successful, false otherwise
+        */
+       public function rename($source, $target) {
+               $this->log("enter: rename('$source', '$target')", Util::DEBUG);
+               try {
+                       $result = $this->share->rename($this->root . $source, $this->root . $target);
+                       $this->removeFromCache($this->root . $source);
+                       $this->removeFromCache($this->root . $target);
+               } catch (AlreadyExistsException $e) {
+                       $this->unlink($target);
+                       $result = $this->share->rename($this->root . $source, $this->root . $target);
+                       $this->removeFromCache($this->root . $source);
+                       $this->removeFromCache($this->root . $target);
+                       $this->swallow(__FUNCTION__, $e);
+               } catch (\Exception $e) {
+                       $this->swallow(__FUNCTION__, $e);
+                       $result = false;
+               }
+               return $this->leave(__FUNCTION__, $result);
+       }
+
+       private function removeFromCache($path) {
+               $path = trim($path, '/');
+               // TODO The CappedCache does not really clear by prefix. It just clears all.
+               //$this->dirCache->clear($path);
+               $this->statCache->clear($path);
+               //$this->xattrCache->clear($path);
+       }
        /**
         * @param string $path
         * @return array