From ea05970f1e7f60fa09752a48de5042b2fc96dc30 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Fri, 2 Jun 2023 22:26:20 +0200 Subject: [PATCH] fix(storage): fallback to copy and unlink when rename fails Signed-off-by: Daniel Kesselberg --- lib/private/Files/Storage/Local.php | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index c0ce0e7021a4e..fb62a53d89407 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -335,7 +335,7 @@ private function checkTreeForForbiddenItems(string $path) { } } - public function rename($source, $target) { + public function rename($source, $target): bool { $srcParent = dirname($source); $dstParent = dirname($target); @@ -361,21 +361,14 @@ public function rename($source, $target) { } if ($this->is_dir($source)) { - // we can't move folders across devices, use copy instead - $stat1 = stat(dirname($this->getSourcePath($source))); - $stat2 = stat(dirname($this->getSourcePath($target))); - if ($stat1['dev'] !== $stat2['dev']) { - $result = $this->copy($source, $target); - if ($result) { - $result &= $this->rmdir($source); - } - return $result; - } - $this->checkTreeForForbiddenItems($this->getSourcePath($source)); } - return rename($this->getSourcePath($source), $this->getSourcePath($target)); + if (@rename($this->getSourcePath($source), $this->getSourcePath($target))) { + return true; + } + + return $this->copy($source, $target) && $this->rmdir($source); } public function copy($source, $target) {