Skip to content

Fix: move file check - #14681

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
Lynn-Inf:fix/move-file
May 8, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
Lynn-Inf:fix/move-file

Conversation

@Lynn-Inf

@Lynn-Inf Lynn-Inf commented May 8, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Restrict file move operations: prevent moving a folder to itself or to one of its own subfolders.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels May 8, 2026
@coderabbitai

coderabbitai Bot commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The move_files function adds validation to reject moving a folder into itself or into its own descendant subfolders by checking destination folder ancestors against source folder IDs.

Changes

Folder Move Validation

Layer / File(s) Summary
Ancestor Validation
api/apps/services/file_api_service.py
Added checks in move_files: reject moves when destination folder ID matches source folder ID, and reject moves when destination is within source folder's descendant chain by computing ancestor IDs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A rabbit guards each folder's place,
No circles in this nested space.
Can't tuck a parent in its child,
Our move validation keeps it mild! 🐰✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Fix: move file check' is vague and generic, using non-descriptive language that doesn't clearly convey what specific check or issue was fixed. Improve the title to be more specific, e.g., 'Prevent moving folders into themselves or their subfolders' or 'Add folder move validation checks'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description includes the required sections ('What problem does this PR solve?' and 'Type of change') with adequate detail about the specific issue being fixed.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

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

@Lynn-Inf Lynn-Inf added the ci Continue Integration label May 8, 2026
@Lynn-Inf
Lynn-Inf marked this pull request as draft May 8, 2026 08:52
@Lynn-Inf
Lynn-Inf marked this pull request as ready for review May 8, 2026 08:52
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 8, 2026

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@api/apps/services/file_api_service.py`:
- Around line 510-520: In move_files, add process logging for the early
rejection cases: when a file in files is the same folder as dest_folder
(currently returning "Cannot move a folder to itself.") and when a source folder
is an ancestor of dest_folder (currently returning "Cannot move a folder into
its own subfolder."); use the same logger used elsewhere in this module (e.g.,
processLogger or module logger) to emit an info/warn log that includes the
source folder id(s) and the destination folder id before each return; reference
the variables files, dest_folder, FileType, and
FileService.get_all_parent_folders to construct messages like "Reject move:
source_folder_id=<id> dest_folder_id=<id> reason=<...>" so both rejection paths
are logged for traceability.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fdde969e-390a-479c-a0b9-4a3e7e58e441

📥 Commits

Reviewing files that changed from the base of the PR and between ce2ec86 and 8dfb07c.

📒 Files selected for processing (1)
  • api/apps/services/file_api_service.py

Comment on lines +510 to +520
if dest_folder:
for file in files:
if file.type == FileType.FOLDER.value and file.id == dest_folder.id:
return False, "Cannot move a folder to itself."
# Check if any source folder is an ancestor of the destination folder
# to prevent infinite recursion in _move_entry_recursive
dest_ancestors = FileService.get_all_parent_folders(dest_folder.id)
dest_ancestor_ids = {f.id for f in dest_ancestors}
for file in files:
if file.type == FileType.FOLDER.value and file.id in dest_ancestor_ids:
return False, "Cannot move a folder into its own subfolder."

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.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add logs for the new rejection paths in move_files.

These new early returns are a new flow and should log the rejection reason (source folder ID + destination folder ID) to improve traceability in production.

Proposed patch
     if dest_folder:
         for file in files:
             if file.type == FileType.FOLDER.value and file.id == dest_folder.id:
+                logging.warning(
+                    "Rejected move: folder cannot be moved into itself (source_id=%s, dest_id=%s)",
+                    file.id,
+                    dest_folder.id,
+                )
                 return False, "Cannot move a folder to itself."
         # Check if any source folder is an ancestor of the destination folder
         # to prevent infinite recursion in _move_entry_recursive
         dest_ancestors = FileService.get_all_parent_folders(dest_folder.id)
         dest_ancestor_ids = {f.id for f in dest_ancestors}
         for file in files:
             if file.type == FileType.FOLDER.value and file.id in dest_ancestor_ids:
+                logging.warning(
+                    "Rejected move: folder cannot be moved into its own subfolder (source_id=%s, dest_id=%s)",
+                    file.id,
+                    dest_folder.id,
+                )
                 return False, "Cannot move a folder into its own subfolder."

As per coding guidelines, **/*.py: Add logging for new flows.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@api/apps/services/file_api_service.py` around lines 510 - 520, In move_files,
add process logging for the early rejection cases: when a file in files is the
same folder as dest_folder (currently returning "Cannot move a folder to
itself.") and when a source folder is an ancestor of dest_folder (currently
returning "Cannot move a folder into its own subfolder."); use the same logger
used elsewhere in this module (e.g., processLogger or module logger) to emit an
info/warn log that includes the source folder id(s) and the destination folder
id before each return; reference the variables files, dest_folder, FileType, and
FileService.get_all_parent_folders to construct messages like "Reject move:
source_folder_id=<id> dest_folder_id=<id> reason=<...>" so both rejection paths
are logged for traceability.

@codecov

codecov Bot commented May 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (94f82ac) to head (8dfb07c).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14681   +/-   ##
=======================================
  Coverage   94.16%   94.16%           
=======================================
  Files          10       10           
  Lines         703      703           
  Branches      112      112           
=======================================
  Hits          662      662           
  Misses         25       25           
  Partials       16       16           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 merged commit ada6d47 into infiniflow:main May 8, 2026
2 checks passed
pekar9781 pushed a commit to pekar9781/ragflow that referenced this pull request May 8, 2026
### What problem does this PR solve?

Restrict file move operations: prevent moving a folder to itself or to
one of its own subfolders.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
Ricardo-M-L pushed a commit to Ricardo-M-L/ragflow that referenced this pull request Aug 17, 2026
### What problem does this PR solve?

Restrict file move operations: prevent moving a folder to itself or to
one of its own subfolders.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants