Skip to content

fix(storage/local): stop deleting prior to forbidden items check - #57421

Open
joshtrichards wants to merge 3 commits into
masterfrom
jtr/fix-storage-local-rename-earlier-forbidden-check
Open

fix(storage/local): stop deleting prior to forbidden items check#57421
joshtrichards wants to merge 3 commits into
masterfrom
jtr/fix-storage-local-rename-earlier-forbidden-check

Conversation

@joshtrichards

@joshtrichardsjoshtrichards commented Jan 8, 2026

Copy link
Copy Markdown
Member

Summary

During rename operations, if something already exists in the destination path, it gets deleted prior to the forbidden items check. If the check doesn't pass, the operation is aborted but deletion has already occurred.

This PR moves the forbidden items check up so it takes place before any destructive activities occur (see checkTreeForForbiddenItems).

The 2nd commit also addresses an edge case where the copy+unlink fallback could still be triggered for case-only renames on case-insensitive filesystems.

Also included throughout:

  • checks success/failure of removals
  • logs removal fails
  • eliminates duplicate code by using remove()
  • adds a logging helper to tidy up readability
  • moves source existence check to the top

TODO

Checklist

…in rename
Signed-off-by: Josh <josh.t.richards@gmail.com>
On case-insensitive filesystems, the copy+unlink fallback shouldn't be attempted since source/destination can "overlap".
Also adds some additional logging for error conditions + one at debug level for a more common scenario.
Otherwise just some additional tidying for readability.
Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichardsjoshtrichards changed the title fix(storage/local): check forbidden items before target deletionfix(storage/local): stop deleting prior to forbidden items checkJan 8, 2026
Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichardsjoshtrichards added this to the Nextcloud 33 milestone Jan 8, 2026
@joshtrichards
joshtrichards marked this pull request as ready for review January 8, 2026 15:56
@joshtrichards
joshtrichards requested a review from a team as a code ownerJanuary 8, 2026 15:56
@joshtrichards
joshtrichards requested review from Altahrim, artonge, nfebe and provokateurin and removed request for a teamJanuary 8, 2026 15:56
return false;
}

$dstParent = dirname($target);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe also rename this variable $targetParent

$this->rmdir($target);
} elseif ($this->is_file($target)) {
$this->unlink($target);
if (!$this->remove($target)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Even if it's current behaviour, I am not sure we need to remove the target when it's a file.
It should be overwritten by the rename. Not sure if it's dependant from filesystem…

Comment on lines +379 to +380
}
if ($copySuccess && !$unlinkSuccess) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
}
if ($copySuccess && !$unlinkSuccess) {
} elseif (!$unlinkSuccess) {

Or maybe with early returns?

This was referenced Jan 9, 2026
This was referenced Jan 20, 2026
This was referenced Jan 29, 2026
This was referenced Feb 11, 2026
@blizzzblizzz modified the milestones: Nextcloud 33, Nextcloud 34Feb 16, 2026
@nextcloud-botnextcloud-bot mentioned this pull request May 27, 2026
@nextcloud-botnextcloud-bot mentioned this pull request Jun 4, 2026
@nextcloud-botnextcloud-bot mentioned this pull request Jun 5, 2026
@nextcloud-botnextcloud-bot mentioned this pull request Jun 8, 2026
@susnuxsusnux added the community pull requests from community label Jun 9, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to reviewWaiting for reviewsbugcommunitypull requests from communityfeature: filesystem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@joshtrichards@Altahrim@susnux@blizzz@nextcloud-bot