Skip to content

Commit 668bed0

Browse files
icewind1991backportbot[bot]
authored andcommitted
fix: add more logging around failed local renames
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent abb0523 commit 668bed0

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

lib/private/Files/Storage/Local.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,18 +354,20 @@ public function rename(string $source, string $target): bool {
354354
$srcParent = dirname($source);
355355
$dstParent = dirname($target);
356356

357+
$logger = Server::get(LoggerInterface::class);
358+
357359
if (!$this->isUpdatable($srcParent)) {
358-
Server::get(LoggerInterface::class)->error('unable to rename, source directory is not writable : ' . $srcParent, ['app' => 'core']);
360+
$logger->error('unable to rename, source directory is not writable : ' . $srcParent, ['app' => 'core']);
359361
return false;
360362
}
361363

362364
if (!$this->isUpdatable($dstParent)) {
363-
Server::get(LoggerInterface::class)->error('unable to rename, destination directory is not writable : ' . $dstParent, ['app' => 'core']);
365+
$logger->error('unable to rename, destination directory is not writable : ' . $dstParent, ['app' => 'core']);
364366
return false;
365367
}
366368

367369
if (!$this->file_exists($source)) {
368-
Server::get(LoggerInterface::class)->error('unable to rename, file does not exists : ' . $source, ['app' => 'core']);
370+
$logger->error('unable to rename, file does not exists : ' . $source, ['app' => 'core']);
369371
return false;
370372
}
371373

@@ -377,20 +379,43 @@ public function rename(string $source, string $target): bool {
377379
}
378380
}
379381

382+
$absoluteSource = $this->getSourcePath($source);
383+
$absoluteTarget = $this->getSourcePath($target);
384+
380385
if ($this->is_dir($source)) {
381-
$this->checkTreeForForbiddenItems($this->getSourcePath($source));
386+
$this->checkTreeForForbiddenItems($absoluteSource);
382387
}
383388

384-
if (@rename($this->getSourcePath($source), $this->getSourcePath($target))) {
389+
if (@rename($absoluteSource, $absoluteTarget)) {
385390
if ($this->caseInsensitive) {
386391
if (mb_strtolower($target) === mb_strtolower($source) && !$this->file_exists($target)) {
387392
return false;
388393
}
389394
}
390395
return true;
396+
} else {
397+
$logger->error('failed to rename ' . $absoluteSource . ' to ' . $absoluteTarget . ', trying copy+delete fallback instead', [
398+
'app' => 'core',
399+
'last_error' => error_get_last(),
400+
]);
391401
}
392402

393-
return $this->copy($source, $target) && $this->unlink($source);
403+
if (!$this->copy($source, $target)) {
404+
$logger->error('failed to copy ' . $absoluteSource . ' to ' . $absoluteTarget . ' as part of rename fallback', [
405+
'app' => 'core',
406+
'last_error' => error_get_last(),
407+
]);
408+
return false;
409+
}
410+
411+
if (!$this->unlink($source)) {
412+
$logger->error('failed to delete ' . $absoluteSource . ' as part of rename fallback', [
413+
'app' => 'core',
414+
'last_error' => error_get_last(),
415+
]);
416+
return false;
417+
}
418+
return true;
394419
}
395420

396421
#[\Override]

0 commit comments

Comments
 (0)