Skip to content

Commit 2e6f548

Browse files
committed
fix(storage): fallback to copy and unlink when rename fails
Signed-off-by: Daniel Kesselberg <[email protected]>
1 parent 7548e62 commit 2e6f548

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

lib/private/Files/Storage/Local.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ private function checkTreeForForbiddenItems(string $path) {
335335
}
336336
}
337337

338-
public function rename($source, $target) {
338+
public function rename($source, $target): bool {
339339
$srcParent = dirname($source);
340340
$dstParent = dirname($target);
341341

@@ -361,21 +361,14 @@ public function rename($source, $target) {
361361
}
362362

363363
if ($this->is_dir($source)) {
364-
// we can't move folders across devices, use copy instead
365-
$stat1 = stat(dirname($this->getSourcePath($source)));
366-
$stat2 = stat(dirname($this->getSourcePath($target)));
367-
if ($stat1['dev'] !== $stat2['dev']) {
368-
$result = $this->copy($source, $target);
369-
if ($result) {
370-
$result &= $this->rmdir($source);
371-
}
372-
return $result;
373-
}
374-
375364
$this->checkTreeForForbiddenItems($this->getSourcePath($source));
376365
}
377366

378-
return rename($this->getSourcePath($source), $this->getSourcePath($target));
367+
if (@rename($this->getSourcePath($source), $this->getSourcePath($target))) {
368+
return true;
369+
}
370+
371+
return $this->copy($source, $target) && $this->rmdir($source);
379372
}
380373

381374
public function copy($source, $target) {

0 commit comments

Comments
 (0)