]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(storage): fallback to copy and unlink when rename fails 38623/head
authorDaniel Kesselberg <mail@danielkesselberg.de>
Fri, 2 Jun 2023 20:26:20 +0000 (22:26 +0200)
committerDaniel <mail@danielkesselberg.de>
Mon, 31 Jul 2023 16:54:21 +0000 (18:54 +0200)
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
lib/private/Files/Storage/Local.php

index c0ce0e7021a4eab2fec17c8ba9c9b016910e5ab6..fb62a53d894073712a67f17a66d9632e0430ea4e 100644 (file)
@@ -335,7 +335,7 @@ class Local extends \OC\Files\Storage\Common {
                }
        }
 
-       public function rename($source, $target) {
+       public function rename($source, $target): bool {
                $srcParent = dirname($source);
                $dstParent = dirname($target);
 
@@ -361,21 +361,14 @@ class Local extends \OC\Files\Storage\Common {
                }
 
                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) {