Repository navigation
fix(services/fs): preserve configured root directory on root delete - #9637
Merged
Merged
Conversation
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>
Xuanwo
reviewed
Dec 4, 2026
Xuanwo
left a comment
Member
There was a problem hiding this comment.
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>
Xuanwo
approved these changes
Dec 4, 2026
Contributor
Author
|
@Xuanwo Thanks for the review! Added the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
FsDeleter::delete_onceresolvespathviaself.core.root_join(&path)?and invokesremove_dir/remove_dir_alldirectly without checking whether the resolved path isself.core.root:op.delete("/")on an empty root removesself.core.rootfrom 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.op.delete_with("/").recursive(true)(orop.remove_all("/")) runstokio::fs::remove_dir_all(&self.core.root), removing the configured root directory itself instead of clearing its children.This aligns
services/fswith the root-preservation semantics established in #9630 (services/baidu-netdisk).What changes are included in this PR?
FsDeleter::remove_entryso single-entry deletion (including symlink-safe handling on Unix and Windows) is shared between root cleanup and regular deletes.p == self.core.rootinFsDeleter::delete_once:Ok(())for non-recursive root deletes, preserving both empty and populated roots.FsDeleter::clear_root, which iteratestokio::fs::read_dir(&self.core.root)and removes direct children while preservingself.core.rootitself (and unlinking symlinks without touching external targets).core/services/fs/src/deleter.rscovering 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, anddelete_with("/").recursive(true)/remove_all("/")clears all entries inside the root without removing the root directory itself.Breaking changes
AI Usage Statement
core/services/fs/src/deleter.rs, wrote failing RED unit tests reproducing root removal on unmodifiedmain, implemented theFsDeleterroot guard andclear_roothelper, and verifiedcargo test -p opendal-service-fs,cargo clippy -p opendal-service-fs --all-targets -- -D warnings, andcargo fmt --all -- --check.