Xuanwo opened a new pull request, #8907:
URL: https://github.com/apache/opendal/pull/8907
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements. You can link an issue to this PR using the GitHub syntax. For
example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #.
# Rationale for this change
Two bugs affect `integrations/dav-server` when backed by `memory`, object
stores, or local `fs`:
1. **Collection shadowing on `open` (`PUT` / `PATCH` / read)**:
`OpendalFile::open` did not check whether a collection already existed at
`{path}/` when opening a path without a trailing slash. Because `memory` and
object stores keep `"dir"` and `"dir/"` as separate keys, `PUT /dir` or
SabreDAV append `PATCH /dir` returned `204 No Content` and wrote a file key
`"dir"` alongside `"dir/"` and `"dir/child.txt"`, shadowing the existing
collection in `metadata` and `PROPFIND`. Direct read `open` on `/dir` also
succeeded lazily instead of returning `FsError::Forbidden`.
2. **Non-empty collection removal in `remove_dir` (`DELETE` with `Depth:
0`)**: `OpendalFs::remove_dir` delegated directly to `Operator::delete` without
checking whether the collection had child entries. For `DELETE /dir/` with
`Depth: 0`, object stores could delete only the directory marker (or no-op) and
return `204 No Content` while leaving children intact, and `memory`/`fs`
surfaced `ErrorKind::Unexpected` (`directory not empty`) as HTTP `500 Internal
Server Error` instead of `FsError::Exists` (HTTP `405 Method Not Allowed`).
# What changes are included in this PR?
- `integrations/dav-server/src/file.rs`:
- Reject empty and trailing-slash paths immediately with
`FsError::Forbidden` in `OpendalFile::open`.
- Add `OpendalFile::dir_exists` checking both `stat("{path}/")` and
`lister_with("{path}/").limit(1)` so both explicit directory markers and
implicit prefixes with children are detected.
- Reject write/append opens targeting an existing collection with
`FsError::Forbidden` (or `FsError::Exists` when `options.create_new` is set)
before opening a writer.
- Validate read opens against `stat` / `dir_exists` so opening an existing
collection returns `FsError::Forbidden` and opening a missing path returns
`FsError::NotFound`, without extra directory checks on existing files.
- `integrations/dav-server/src/fs.rs`:
- Reject root removal (`/`) with `FsError::Forbidden` in
`OpendalFs::remove_dir`.
- Check for child entries with `lister_with(&dir_path).limit(2)` and
return `FsError::Exists` if any entry other than `dir_path` itself is present.
- Reject removing a file through `remove_dir` with `FsError::Forbidden`,
while keeping missing-marker deletion idempotent so `dav-server`'s `Depth:
infinity` `DELETE` on implicit object-store directories continues to succeed
(top-level `DELETE /missing/` returns `404` from `handle_delete`'s
`symlink_metadata` check).
- `integrations/dav-server/tests/test.rs`:
- Add deterministic `DavHandler` and `DavFileSystem` regression tests
covering both `Memory` and `Fs` backends for `PUT` / `PATCH` / `open` against
explicit and implicit collections, and `Depth: 0` / `Depth: infinity` `DELETE`
and `remove_dir` behavior.
# Are there any user-facing changes?
- `PUT` and SabreDAV append `PATCH` targeting an existing collection URI
without a trailing slash now return `403 Forbidden` instead of creating a
shadowing file key.
- `DELETE` with `Depth: 0` against a non-empty collection now returns `405
Method Not Allowed` (`FsError::Exists`) instead of succeeding or returning `500
Internal Server Error`.
# Breaking changes
# AI Usage Statement
- **Harness:** pi
- **Model:** Gemini 4 Neon
- **Effort:** High
- **Role:** Reproduced both bugs with failing tests, implemented the fixes
in `OpendalFile::open` and `OpendalFs::remove_dir`, and added regression tests
over the `Memory` and `Fs` backends. Note for reviewers:
`OpendalFs::remove_dir` keeps missing directory markers idempotent (rather than
returning `FsError::NotFound`) because `dav-server`'s `Depth: infinity`
`DELETE` calls `remove_dir` after removing the last child of an implicit
object-store prefix, while `handle_delete` already checks `symlink_metadata`
and returns `404` for missing targets.
--
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]