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 Jun 26, 2023
1 parent 9751303 commit ea05970
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions lib/private/Files/Storage/Local.php
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))) {

Check failure

Code scanning / Psalm

TaintedFile Error

Detected tainted file handling

Check failure

Code scanning / Psalm

TaintedFile Error

Detected tainted file handling
return true;
}

return $this->copy($source, $target) && $this->rmdir($source);
}

public function copy($source, $target) {
Expand Down

0 comments on commit ea05970

Please sign in to comment.