Skip to content

fix(file): reject moving a folder together with its descendants - #20848

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
flyingwhit:fix/move-file-panic
Oct 13, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
flyingwhit:fix/move-file-panic

Conversation

@flyingwhit

Copy link
Copy Markdown
Contributor

Summary

FileService.MoveFiles processed every src_file_ids entry independently, but moveEntryRecursive already relocates and deletes an entire subtree. Selecting a folder together with one of its descendants therefore processed the descendant twice: its row was already gone, so the second pass recreated an empty duplicate folder under the destination, and for a nested file it attempted a storage move from an already-removed source.

This change adds a fail-fast source-level check. MoveFiles now rejects any request whose selected entries contain an ancestor/descendant relationship (folder + subfolder, folder + grandchild, folder + contained file, any depth) before any storage or database mutation, returning cannot move a folder together with its descendant. The check is order-independent and reused the existing ancestry helper.

@flyingwhit flyingwhit added the ci Continue Integration label Oct 12, 2026
@flyingwhit
flyingwhit requested a review from wangq8 October 12, 2026 11:39
@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 81311a49-c355-410c-ab8f-4fc69f46ec76

📥 Commits

Reviewing files that changed from the base of the PR and between aa81851 and f64237f.


📒 Files selected for processing (2)
  • internal/service/file/file_folder.go
  • internal/service/file/file_folder_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.



📝 Walkthrough

Walkthrough

MoveFiles now rejects selections that contain an entry and one of its ancestors. Tests cover nested sources in either order, unrelated entries, and moving a single folder with its subtree.

Changes

MoveFiles source validation

Layer / File(s) Summary
Check selected sources for ancestry
internal/service/file/file_folder.go, internal/service/file/file_folder_test.go
MoveFiles checks source ancestry after permission checks and returns an error when the selection includes a folder and its descendant. Tests verify nested selections are rejected without moving entries, while unrelated entries and a single folder with its subtree can still move.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: euvre


Merge Risk: ⚪ Minimal · up to f6423

This change makes the file service reject a move that selects a folder together with one of its descendants, which prevents duplicate or failed processing. No concrete merge-blocking risk was found. Bulk moves of very large selections may do extra ancestor lookups, but this is unconfirmed and not blocking.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 72.73% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely states the main change: rejecting moves that select a folder together with its descendants.
Description check Passed The description includes the required Summary section and clearly explains the problem, affected API, behavior, error message, scope, and fail-fast timing.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

  • Fix all pre-merge checks with AI
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks each folder’s trail
To keep a nested move from fail.
Two branches travel side by side,
One folder brings its tree along for the ride.
The burrow’s paths stay neat and clear.

Comment @coderabbitai help to get the list of available commands.

@wangq8
wangq8 merged commit ed0fd78 into infiniflow:main Oct 13, 2026
6 checks passed
RerankerGuo added a commit to RerankerGuo/ragflow that referenced this pull request Oct 13, 2026
…lt window

Adds TestDeleteStructureForDocs_FindsGhostsPastResultWindow, contributed by
@Xavierando in the PR thread: a windowEngine fake pages like the
Elasticsearch engine (unsorted from+size requests fail past
index.max_result_window, sorted requests walk past it via search_after),
and a ghost row sorted past the window must still be found and deleted.

Verified to fail on main without this PR's Asc("id") on the ghost scan and
to pass on this branch.

Also merges upstream/main (ed0fd78) to pick up office_oxide v0.1.12 and
the infiniflow#20750/infiniflow#20848 changes; both affected packages pass:
  go test ./internal/ingestion/knowledge_compile/ ./internal/engine/elasticsearch/
RerankerGuo added a commit to RerankerGuo/ragflow that referenced this pull request Oct 28, 2026
…lt window

Adds TestDeleteStructureForDocs_FindsGhostsPastResultWindow, contributed by
@Xavierando in the PR thread: a windowEngine fake pages like the
Elasticsearch engine (unsorted from+size requests fail past
index.max_result_window, sorted requests walk past it via search_after),
and a ghost row sorted past the window must still be found and deleted.

Verified to fail on main without this PR's Asc("id") on the ghost scan and
to pass on this branch.

Also merges upstream/main (ed0fd78) to pick up office_oxide v0.1.12 and
the infiniflow#20750/infiniflow#20848 changes; both affected packages pass:
  go test ./internal/ingestion/knowledge_compile/ ./internal/engine/elasticsearch/
RerankerGuo added a commit to RerankerGuo/ragflow that referenced this pull request Nov 18, 2026
…lt window

Adds TestDeleteStructureForDocs_FindsGhostsPastResultWindow, contributed by
@Xavierando in the PR thread: a windowEngine fake pages like the
Elasticsearch engine (unsorted from+size requests fail past
index.max_result_window, sorted requests walk past it via search_after),
and a ghost row sorted past the window must still be found and deleted.

Verified to fail on main without this PR's Asc("id") on the ghost scan and
to pass on this branch.

Also merges upstream/main (ed0fd78) to pick up office_oxide v0.1.12 and
the infiniflow#20750/infiniflow#20848 changes; both affected packages pass:
  go test ./internal/ingestion/knowledge_compile/ ./internal/engine/elasticsearch/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants