Xuanwo opened a new pull request, #8913:
URL: https://github.com/apache/opendal/pull/8913
# Which issue does this PR close?
None. Found during maintenance; no separate issue was filed.
# Rationale for this change
With the default `root = "/"`, `build_absolute_path("/", "/")` produces an
empty string `""`. This caused three related root-directory bugs across local
KV services (the same bug class fixed for `memory` in #8863):
1. `Writer::close` in `moka`, `mini_moka`, `dashmap`, `sled`, and `redb`
only checked `self.path.ends_with('/')`, missing `self.path.is_empty()`.
Writing the root directory marker via `create_dir("/")` therefore produced
`EntryMode::FILE` metadata (and stored it as a file in metadata-storing
backends).
2. `SledLister::next` derived `EntryMode` from `key.ends_with('/')` (`false`
for `""`) before `oio::Entry::new` normalized the empty relative path to `"/"`.
In debug/test builds this panicked on `debug_assert!(meta.mode().is_dir() ==
path.ends_with('/'))`, and in release builds it emitted `("/",
EntryMode::FILE)`.
3. `Service::stat` in `mini_moka` and `dashmap` lacked a root-path check (`p
== build_absolute_path(&self.root, "")`), causing raw `Service::stat("/")` (or
`Operator::stat("/")` without `SimulateLayer`) to return `NotFound` before
`create_dir("/")` and `EntryMode::FILE` afterward.
# What changes are included in this PR?
- **Writers (`moka`, `mini_moka`, `dashmap`, `sled`, `redb`)**: treat
`self.path.is_empty() || self.path.ends_with('/')` as a directory
(`MetadataBuilder::dir()`) in `Writer::close`.
- **Listers (`sled`, `dashmap`)**: normalize empty relative paths to `"/"`
before constructing `oio::Entry`, and derive `MetadataBuilder::dir()` from the
normalized path in `SledLister::next` (matching `memory` and `redb`).
- **Stat (`mini_moka`, `dashmap`)**: return `MetadataBuilder::dir()` when `p
== build_absolute_path(&self.root, "")` (matching `memory`, `moka`, `sled`, and
`redb`).
- **Tests (`moka`, `mini_moka`, `dashmap`, `sled`, `redb`)**: add regression
tests covering `create_dir("/")` + `list("/")` (flat and recursive) and raw
`Service::stat("/")` / `Writer::close` metadata for `root` in `["/", "/sub/"]`.
# Are there any user-facing changes?
Fixes `create_dir("/")`, `list("/")`, and raw `stat("/")` on `moka`,
`mini_moka`, `dashmap`, `sled`, and `redb` when configured with the default
root (`"/"`).
# Breaking changes
# AI Usage Statement
- Harness: pi
- Model: Gemini 4 Neon
- Effort: high
- Role: Verified the root-directory metadata, listing, and stat failures
across `moka`, `mini_moka`, `dashmap`, `sled`, and `redb`, implemented the
fixes and regression tests, and ran local formatting, clippy, unit test, and
rustdoc checks. `rocksdb` was excluded from this PR because `libclang`
development files were unavailable in the local build environment to compile
and verify it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]