Merge pull request #38623 from nextcloud/fix/14743/rename-fallback-copy-unlink

fix(storage): fallback to copy and unlink when rename fails
This commit is contained in:
Daniel 2023-07-31 21:04:07 +02:00 committed by GitHub
commit 27916deb95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View 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) {