Skip to content

fix(Files/Cache): align MoveFromCacheTrait fallback validation with Cache::moveFromCache#59916

Open
joshtrichards wants to merge 2 commits intomasterfrom
jtr/fix-MoveFromCacheTrait-hardening
Open

fix(Files/Cache): align MoveFromCacheTrait fallback validation with Cache::moveFromCache#59916
joshtrichards wants to merge 2 commits intomasterfrom
jtr/fix-MoveFromCacheTrait-hardening

Conversation

@joshtrichards
Copy link
Copy Markdown
Member

@joshtrichards joshtrichards commented Apr 26, 2026

Summary

Validate the source cache entry in MoveFromCacheTrait::moveFromCache() before attempting the fallback copy-then-delete move.

Why

The fallback path should fail consistently when the source entry does not exist, rather than relying on a less specific downstream failure. This also keeps the trait behavior aligned with Cache::moveFromCache().

Behavior change

Low risk:

  • If the source path is missing, this moveFromCache() now throws a clearer RuntimeException immediately.
  • This matches the validation already performed by Cache::moveFromCache().
  • The observable behavior is unchanged for callers that already depended on an exception; only the failure location and message are improved.

TODO

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

…e source entry

Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichards
Copy link
Copy Markdown
Member Author

An side: MoveFromCacheTrait currently appears to be an implementation detail of OC\Files\Cache\Cache rather than a reusable trait.

Since it is only used in production by Cache, I lean toward folding the fallback into the class itself to make ownership and behavior clearer.

I was initially confused about its use case, since no production code uses the trait other than Cache (which I wouldn’t have expected to need the fallback), but then I realized that the source caches that may use this fallback still ultimately flow through Cache, which is the one responsible for deciding whether to use the fallback or not.

Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichards joshtrichards changed the title fix(Files/Cache): harden MoveFromCacheTrait::moveFromCache to validate source entry fix(Files/Cache): align MoveFromCacheTrait fallback with Cache::moveFromCache validation Apr 26, 2026
@joshtrichards joshtrichards changed the title fix(Files/Cache): align MoveFromCacheTrait fallback with Cache::moveFromCache validation fix(Files/Cache): align MoveFromCacheTrait fallback validation with Cache::moveFromCache Apr 26, 2026
@joshtrichards joshtrichards added this to the Nextcloud 34 milestone Apr 26, 2026
@joshtrichards joshtrichards marked this pull request as ready for review April 26, 2026 15:05
@joshtrichards joshtrichards requested a review from a team as a code owner April 26, 2026 15:05
@joshtrichards joshtrichards requested review from ArtificialOwl, artonge, provokateurin and salmart-dev and removed request for a team April 26, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant