Skip to content

fix(services/fs): preserve configured root directory on root delete - #9637

Merged
Xuanwo merged 2 commits into
apache:mainfrom
xgbtxy:fix/fs-preserve-root-on-delete
Dec 4, 2026
Merged

Xuanwo merged 2 commits into
apache:mainfrom
xgbtxy:fix/fs-preserve-root-on-delete

Conversation

@xgbtxy

@xgbtxy xgbtxy commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

FsDeleter::delete_once resolves path via self.core.root_join(&path)? and invokes remove_dir / remove_dir_all directly without checking whether the resolved path is self.core.root:

  • Calling op.delete("/") on an empty root removes self.core.root from disk, and calling it on a populated root fails with a directory-not-empty error instead of keeping non-recursive root deletion as a safe no-op.
  • Calling op.delete_with("/").recursive(true) (or op.remove_all("/")) runs tokio::fs::remove_dir_all(&self.core.root), removing the configured root directory itself instead of clearing its children.

This aligns services/fs with the root-preservation semantics established in #9630 (services/baidu-netdisk).

What changes are included in this PR?

  • Extract FsDeleter::remove_entry so single-entry deletion (including symlink-safe handling on Unix and Windows) is shared between root cleanup and regular deletes.
  • Guard p == self.core.root in FsDeleter::delete_once:
    • Return Ok(()) for non-recursive root deletes, preserving both empty and populated roots.
    • Delegate recursive root deletes to FsDeleter::clear_root, which iterates tokio::fs::read_dir(&self.core.root) and removes direct children while preserving self.core.root itself (and unlinking symlinks without touching external targets).
  • Add unit tests in core/services/fs/src/deleter.rs covering non-recursive empty/populated root deletion, recursive root cleanup preserving the root and external siblings, and Unix directory symlink unlinking under recursive root cleanup.

Are there any user-facing changes?

Yes. On services/fs, delete("/") is now a safe no-op that preserves the configured root directory and its contents, and delete_with("/").recursive(true) / remove_all("/") clears all entries inside the root without removing the root directory itself.

Breaking changes

AI Usage Statement

  • Harness: Antigravity
  • Model: Gemini 3.1 Pro
  • Effort: High
  • Role: Audited core/services/fs/src/deleter.rs, wrote failing RED unit tests reproducing root removal on unmodified main, implemented the FsDeleter root guard and clear_root helper, and verified cargo test -p opendal-service-fs, cargo clippy -p opendal-service-fs --all-targets -- -D warnings, and cargo fmt --all -- --check.

Guard root deletion in FsDeleter::delete_once when the resolved target equals self.core.root so non-recursive root deletes are a safe no-op and recursive root deletes clear direct children while keeping the configured root directory intact.

Signed-off-by: Yan Chen <yan8925298@gmail.com>
Copilot AI balanced review requested due to automatic review settings December 4, 2026 00:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add the / case to ## Delete in core/services/fs/src/docs.md? That section currently says recursive deletion removes the named directory itself. For the configured root, a non-recursive delete succeeds and leaves the root and its contents intact. A recursive delete clears its children and preserves the root. Both behaviors passed on ext4.

AI-generated review comment.

Add the / case to `## Delete` in `core/services/fs/src/docs.md` so non-recursive and recursive root deletion semantics are documented.

Signed-off-by: Yan Chen <yan8925298@gmail.com>
@github-actions github-actions Bot added releases-note/fix The PR fixes a bug or has a title that begins with "fix" services/fs size:L This PR changes 100-499 lines, ignoring generated files. labels Dec 4, 2026
@Xuanwo
Xuanwo merged commit 643e221 into apache:main Dec 4, 2026
47 checks passed
@xgbtxy

xgbtxy commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@Xuanwo Thanks for the review! Added the / non-recursive and recursive delete semantics under ## Delete in core/services/fs/src/docs.md in 2081564 (check_docs passed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

releases-note/fix The PR fixes a bug or has a title that begins with "fix" services/fs size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(services/fs): deleting "/" removes the configured root directory

3 participants