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

Open Beginner friendly
#9,635 1 comment 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

@xgbtxy is already working on this.

Since Dec 4, 2026.

  • #9637 by @xgbtxy — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
81/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
backend

Research direction

Start in core/services/fs/src/deleter.rs, at FsDeleter::delete_once, and check how root_join resolves / before the filesystem removal. Reproduce both cases from the issue: non-recursive deletion on empty and populated roots, and recursive deletion after writing a file. Done means non-recursive root deletion preserves the root and recursive deletion clears its children while preserving the root directory.

Written by the indexing model from the issue text.

Description

Describe the bug

In core/services/fs/src/deleter.rs, FsDeleter::delete_once resolves path via self.core.root_join(&path)? and removes the resulting path directly without checking whether it resolves to self.core.root:

  1. op.delete("/") (non-recursive) on an empty root runs tokio::fs::remove_dir(&self.core.root), removing the configured root directory itself from disk (and failing with a directory-not-empty error on a populated root instead of keeping non-recursive root deletion as a safe no-op).
  2. op.delete_with("/").recursive(true) (and op.remove_all("/")) runs tokio::fs::remove_dir_all(&self.core.root), deleting the configured root directory itself rather than clearing its children.
Steps to Reproduce
let temp_dir = tempfile::tempdir().unwrap();
let root = temp_dir.path().join("root");
let op = Operator::new(Fs::default().root(root.to_str().unwrap())).unwrap();

op.delete("/").await.unwrap();
assert!(root.is_dir()); // fails: configured root directory was removed

let op = Operator::new(Fs::default().root(root.to_str().unwrap())).unwrap();
op.write("file.txt", "hello").await.unwrap();
op.delete_with("/").recursive(true).await.unwrap();
assert!(root.is_dir()); // fails: configured root directory was removed
Expected Behavior

Matching root-preservation semantics (see #9630):

  • Non-recursive delete("/") should be a safe no-op that preserves both empty and populated configured roots.
  • Recursive delete_with("/").recursive(true) should clear all children inside the configured root (unlinking symlinks without touching external targets) while preserving the configured root directory itself.
AI Usage Statement
  • Harness: Antigravity
  • Model: Gemini 3.1 Pro
  • Effort: High
  • Role: Identified the missing root guard in FsDeleter::delete_once, reproduced both non-recursive and recursive root deletion failures locally, and drafted this report.
Dominant language
Rust
Stars
5.5k
Forks
869
Avg merge
8h 2m
Merged PRs (30d)
862

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/opendal

All issues in apache/opendal

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.