Skip to content

fix(storage): fallback to copy and unlink when rename fails - #38623

Merged
kesselb merged 1 commit into
masterfrom
fix/14743/rename-fallback-copy-unlink
Jul 31, 2023
Merged

fix(storage): fallback to copy and unlink when rename fails#38623
kesselb merged 1 commit into
masterfrom
fix/14743/rename-fallback-copy-unlink

Conversation

@kesselb

@kesselbkesselb commented Jun 2, 2023

Copy link
Copy Markdown
Contributor

Summary

Alternative approach to #19289

If you use docker's OverlayFS and mount two folders into your container from the same disk it's also not possible to rename, but $stat['dev'] is equal.1

Many thanks again to @kubatek94 for the initial pull request.

TODO

  • CI

Checklist

Footnotes

  1. https://docs.docker.com/storage/storagedriver/overlayfs-driver/#modifying-files-or-directories

Comment threadlib/private/Files/Storage/Local.php Fixed
Comment threadlib/private/Files/Storage/Local.php Fixed
@kesselb
kesselbforce-pushed the fix/14743/rename-fallback-copy-unlink branch from a890d67 to 083c869CompareJune 2, 2023 21:10
}

return rename($this->getSourcePath($source), $this->getSourcePath($target));
if (@rename($this->getSourcePath($source), $this->getSourcePath($target))) {

Check failure

Code scanning / Psalm

TaintedFile

Detected tainted file handling
}

return rename($this->getSourcePath($source), $this->getSourcePath($target));
if (@rename($this->getSourcePath($source), $this->getSourcePath($target))) {

Check failure

Code scanning / Psalm

TaintedFile

Detected tainted file handling
@szaimenszaimen added the 2. developing Work in progress label Jun 2, 2023
@szaimenszaimen added this to the Nextcloud 28 milestone Jun 2, 2023
@solracsf

This comment was marked as resolved.

@kesselb
kesselbforce-pushed the fix/14743/rename-fallback-copy-unlink branch from 083c869 to 9122df3CompareJune 2, 2023 22:03
Comment threadlib/private/Files/Storage/Local.php
@kesselbkesselb self-assigned this Jun 3, 2023
@kesselbkesselb added bug 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jun 3, 2023
}

public function rename($source, $target) {
public function rename($source, $target): bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice opportunity to type the function params

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
@kesselb
kesselbforce-pushed the fix/14743/rename-fallback-copy-unlink branch from 2e6f548 to b4ff557CompareJuly 31, 2023 16:54
@kesselb
kesselb merged commit 27916de into masterJul 31, 2023
@kesselb
kesselb deleted the fix/14743/rename-fallback-copy-unlink branch July 31, 2023 19:04
@kesselb

kesselb commented Jul 31, 2023

Copy link
Copy Markdown
ContributorAuthor

Follow-up to change rmdir to unlink: #39644

@szaimen

Copy link
Copy Markdown
Contributor

🎉🎉🎉

QUIQQER pushed a commit to QUIQQER/QUtils that referenced this pull request Jan 19, 2024
This could happen if a folder is mounted to another drive.
The media folder is a good example for this.
The problem also occurs in plain Docker containers.
The docker magic seems to create different filesystems.
This is a known problem (& solution), see:
- nextcloud/server#38623
- https://bugs.php.net/bug.php?id=54097
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to reviewWaiting for reviewsbug

Projects

None yet

6 participants

@kesselb@solracsf@szaimen@nfebe@github-advanced-security@come-nc