diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index e0688a345a60..7d0df7d7922c 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -261,11 +261,22 @@ public function rename($source, $target) { $this->removeFromCache($this->root . $source); $this->removeFromCache($this->root . $target); } catch (AlreadyExistsException $e) { + $this->swallow(__FUNCTION__, $e); $this->unlink($target); $result = $this->share->rename($this->root . $source, $this->root . $target); $this->removeFromCache($this->root . $source); $this->removeFromCache($this->root . $target); + } catch (Exception $e) { $this->swallow(__FUNCTION__, $e); + // Icewind\SMB\Exception\Exception, not a plain exception + if ($e->getCode() === 22) { + $this->unlink($target); + $result = $this->share->rename($this->root . $source, $this->root . $target); + $this->removeFromCache($this->root . $source); + $this->removeFromCache($this->root . $target); + } else { + $result = false; + } } catch (\Exception $e) { $this->swallow(__FUNCTION__, $e); $result = false;