diff options
author | Jörn Friedrich Dreyer <jfd@butonic.de> | 2016-08-16 15:22:45 +0200 |
---|---|---|
committer | Jörn Friedrich Dreyer <jfd@butonic.de> | 2016-08-26 09:38:01 +0200 |
commit | f4051a13346d619d9e083baeb09a50ef1cd59bc8 (patch) | |
tree | 2d02226e4a7739481307e0001262fa85845e11b2 | |
parent | baec3a0c1301b31ea6355ea331e4920562dcf967 (diff) | |
download | nextcloud-server-f4051a13346d619d9e083baeb09a50ef1cd59bc8.tar.gz nextcloud-server-f4051a13346d619d9e083baeb09a50ef1cd59bc8.zip |
overwrite target on rename
-rw-r--r-- | apps/files_external/lib/smb.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php index c60f096c657..2a4ae53bcf4 100644 --- a/apps/files_external/lib/smb.php +++ b/apps/files_external/lib/smb.php @@ -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; @@ -189,6 +190,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 */ |