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

   # Which issue does this PR close?
   
   None.
   
   # Rationale for this change
   
   `opendal-service-ftp` has four correctness and reliability bugs across 
listing, FTPS TLS setup, deletion, and connection/error handling:
   
   1. **Listing `.`/`..`, POSIX `"total N"` headers, and `550` missing 
directories**:
      - FTP servers such as `vsftpd` (with `force_dot_files=YES`), ProFTPD, and 
Pure-FTPd emit `.` and `..` directory entries in `LIST` output. Returning them 
as `Dir` entries causes simulated recursive `list` and 
`delete_with(...).recursive(true)` to loop indefinitely or traverse above the 
target directory.
      - POSIX `LIST` summary headers (`total N`) fail POSIX/DOS parsing in 
`suppaftp` and fall back to its MLST parser, turning them into phantom 0-byte 
files named `"total N"`.
      - Returning `550 FileUnavailable` when listing a non-existent directory 
propagated `ErrorKind::NotFound` instead of returning an empty listing per 
OpenDAL's `list` contract.
   2. **FTPS certificate loading panics**:
      - `Manager::create` called 
`rustls_native_certs::load_native_certs().expect(...)` and 
`root_store.add(cert).unwrap()` on every new connection, panicking on any 
certificate store warning or single unparsable OS certificate.
   3. **Silent failure on `550 FileUnavailable` during delete**:
      - `FtpDeleter::delete_once` treated every `550` reply from `RMD` / `DELE` 
as `Ok(())`, silently reporting success when deleting a non-empty directory, a 
mismatched file/directory path, or an entry lacking permissions.
   4. **Non-recursive root creation and error classification**:
      - `Manager::create` called a single `mkdir(&self.root)`, failing when 
configuring a multi-level non-existent `root`.
      - `format_ftp_error` mapped `530 NotLoggedIn` to `ErrorKind::Unexpected` 
instead of `ErrorKind::PermissionDenied`, and did not mark transient 4xx 
replies or transient `FtpError::ConnectionError` I/O errors as temporary for 
`RetryLayer`.
   
   # What changes are included in this PR?
   
   - **`core/services/ftp/src/lister.rs`, `core/services/ftp/src/reader.rs`, 
`core/services/ftp/src/backend.rs`**:
     - Added `parse_list_line` to skip blank lines, POSIX `"total N"` summary 
headers, and `.` / `..` entries before yielding entries in `FtpLister` and 
matching entries in `FtpBackend::ftp_stat`.
     - Updated `FtpLazyLister::inner` to treat `550 FileUnavailable` on `LIST` 
as an empty directory listing.
   - **`core/services/ftp/src/core.rs`, `core/services/ftp/src/backend.rs`**:
     - Added `build_tls_config` to load native root certificates once in 
`FtpBuilder::build` using `RootCertStore::add_parsable_certificates`, logging 
warnings for load/parse errors and returning `ErrorKind::Unexpected` instead of 
panicking when no usable certificates are loaded.
     - Added `create_root_dirs` to create multi-level `root` directories 
component-by-component in `Manager::create`.
     - Updated `format_ftp_error` to map `530 NotLoggedIn`, `532 
StoringNeedAccount`, and `430 InvalidCredentials` to permanent 
`ErrorKind::PermissionDenied`, mark transient 4xx replies (`421`, `425`, `426`, 
`434`, `450`, `451`, `452`) as temporary, and classify 
`FtpError::ConnectionError` I/O errors so transient network failures are 
retryable.
   - **`core/services/ftp/src/deleter.rs`**:
     - Updated `FtpDeleter::delete_once` so `550 FileUnavailable` verifies 
whether the target still exists before returning `Ok(())`: missing targets 
remain idempotent, while existing entries return `ErrorKind::NotADirectory`, 
`ErrorKind::IsADirectory`, or `ErrorKind::Unexpected` with the original `550` 
error attached.
   - **Tests (`core/services/ftp/src/{backend,core,deleter,lister}.rs`, 
`core/services/ftp/Cargo.toml`)**:
     - Added unit and local mock-FTP protocol tests covering `.`/`..` and 
`"total N"` filtering, `550` missing-directory listing, non-panicking TLS cert 
loading, `550` delete verification, multi-level root creation, and FTP error 
classification.
     - Verified live against `fauria/vsftpd` (both default configuration and 
with `force_dot_files=YES`).
   
   # Are there any user-facing changes?
   
   - `FtpBuilder::build` now validates and loads native TLS root certificates 
when FTPS is enabled rather than panicking on first connection if native 
certificate loading fails.
   - Deleting a non-empty directory or an existing undeletable target on FTP 
now returns an error instead of silently returning `Ok(())`.
   - Listing a non-existent directory on servers returning `550` now returns an 
empty list, and `.`/`..` and POSIX `"total N"` lines are no longer returned as 
entries.
   - Multi-level non-existent `root` paths are now created automatically on 
connect, `530` authentication errors return `ErrorKind::PermissionDenied`, and 
transient 4xx / connection errors are marked temporary for retries.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: pi
   - Model: Gemini 4 Neon
   - Effort: high
   - Role: Investigated and verified the four FTP service bugs against 
`origin/main` and a local `vsftpd` container (default and 
`force_dot_files=YES`), implemented the fixes and unit/protocol tests, and ran 
formatting, clippy, doc, unit, and live `vsftpd` checks. Note that three 
pre-existing behavior tests (`test_list_rich_dir`, `test_list_empty_dir`, 
`test_list_nested_dir`) still fail against `vsftpd` because `FtpLister` does 
not synthesize a self-entry for the listed directory, which is outside the 
scope of these fixes.
   


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