Xuanwo opened a new pull request, #8905:
URL: https://github.com/apache/opendal/pull/8905

   # 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.
   -->
   
   None.
   
   # Rationale for this change
   
   `unftp-sbe-opendal` had two groups of FTP `StorageBackend` contract bugs:
   
   1. **Parent-directory (`..`) path traversal broke navigation and could 
corrupt object-store namespaces.** `libunftp` passes joined paths such as 
`/dir/..` and `/dir/../top.txt` without collapsing `..`, and OpenDAL's 
`normalize_path` preserves `..` verbatim. On `services::Fs`, `confined_join` 
rejects `Component::ParentDir` with `NotFound`, breaking `CWD ..` and relative 
parent operations (`RETR`/`STOR`/`LIST`/`DELE`). On object-store-like backends 
such as `services::Memory`, `STOR /dir/../escape.txt` and `STOR 
/../../escape.txt` wrote literal `..` keys instead of clamping to root, and 
`RMD /dir/..` bypassed the `/` root guard.
   2. **Delete, rename, and error mapping violated `unftp-core` / RFC 959 
contracts.**
      - `StorageBackend::del` forwarded directly to OpenDAL's idempotent 
`Operator::delete`, returning `Ok(())` (`250`) for missing files and allowing 
deletion of directories or directory markers.
      - `StorageBackend::rename` passed trailing-slash directory paths (such as 
`RNFR /dir/` + `RNTO /dir2/`) directly to `Operator::rename`, which rejects 
trailing slashes with `IsADirectory` even on rename-capable backends like 
`services::Fs`.
      - `convert_err` mapped `ErrorKind::Unsupported`, 
`ErrorKind::IsADirectory`, and `ErrorKind::NotADirectory` to 
`storage::ErrorKind::LocalError` (`451`) instead of `CommandNotImplemented` 
(`502`) and `PermanentFileNotAvailable` (`550`).
   
   # What changes are included in this PR?
   
   - Lexically normalize `.` and `..` segments in `convert_path`, clamping `..` 
at the FTP root (`/`), stripping leading slashes for non-root paths, and 
preserving trailing slashes for directory paths (including paths ending in `.` 
or `..`). Remove redundant `opendal::raw::normalize_path` calls in 
`StorageBackend` methods.
   - Update `convert_err` to map `ErrorKind::Unsupported` to 
`storage::ErrorKind::CommandNotImplemented` (`502`) and 
`ErrorKind::IsADirectory` / `ErrorKind::NotADirectory` to 
`storage::ErrorKind::PermanentFileNotAvailable` (`550`).
   - Update `StorageBackend::del` to check delete capability, reject directory 
paths and `stat` directory targets with `PermanentFileNotAvailable`, and report 
missing files as `PermanentFileNotAvailable` instead of succeeding as a no-op.
   - Update `StorageBackend::rename` to check rename capability 
(`CommandNotImplemented`), reject root renames (`/`), and allow stripping 
trailing slashes only after confirming via `stat` that the source path is a 
directory (while rejecting trailing-slash renames of regular files).
   - Add unit tests for `convert_path` and `convert_err`, integration tests on 
both `services::Fs` and `services::Memory`, and a loopback FTP test covering 
`CWD ..`, `DELE` error handling, and trailing-slash directory `RNFR`/`RNTO`.
   
   # Are there any user-facing changes?
   
   Yes:
   - FTP paths containing `.` and `..` now resolve lexically and clamp at the 
FTP root across backends.
   - `DELE` on missing files or directories now returns `550` 
(`PermanentFileNotAvailable`) instead of succeeding or deleting directories.
   - `RNFR`/`RNTO` with trailing slashes now succeeds for directories on 
rename-capable backends and returns `502` (`CommandNotImplemented`) on backends 
without rename support.
   - `Unsupported` backend errors now return `502` and 
`IsADirectory`/`NotADirectory` errors now return `550` instead of `451`.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: pi
   - Model: Gemini 4 Neon
   - Effort: High
   - Role: Reproduced the reported bugs with failing tests first, implemented 
the path normalization, `del`, `rename`, and `convert_err` fixes in 
`integrations/unftp-sbe`, and added unit, backend integration, and FTP loopback 
tests.
   


-- 
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]

Reply via email to