Skip to content

Commit

Permalink
fix(storage): fallback to copy and unlink when rename fails
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
  • Loading branch information
kesselb committed Jul 24, 2023
1 parent 7548e62 commit 2e6f548
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) {
Expand Down

0 comments on commit 2e6f548

Please sign in to comment.