Skip to content

refactor(webdav): migrate protocol logic to aster_forge_webdav crate#431

Closed
AptS-1547 wants to merge 1 commit into
masterfrom
feat/issue-428-webdav-crate
Closed

refactor(webdav): migrate protocol logic to aster_forge_webdav crate#431
AptS-1547 wants to merge 1 commit into
masterfrom
feat/issue-428-webdav-crate

Conversation

@AptS-1547

@AptS-1547 AptS-1547 commented Jul 24, 2026

Copy link
Copy Markdown
Member
  • Remove local implementations of DavPath, DavFileSystem, DavLockSystem, and related traits from src/webdav/dav.rs; replace all imports with aster_forge_webdav::dav
  • Delete in-tree WebDAV protocol modules (props, protocol, responses, resources, locks, transfer, deltav) and delegate the full protocol exchange to aster_forge_webdav::handler::WebDavHandler
  • Add aster_forge_webdav dependency to Cargo.toml
  • Replace local is_system_namespace, is_dav_namespace, and is_protected_namespace helpers in property.rs with imports from aster_forge_webdav
  • Replace local normalize_path, path_ancestors, lock_paths_overlap, lock_path_is_under, and unlock_request_targets_lock_scope helpers in db_lock_system.rs with imports from aster_forge_webdav::lock_paths
  • Replace local parse_basic_authorization / base64 decoding in auth.rs with aster_forge_webdav::auth::parse_basic_authorization
  • Introduce DavPropertyTarget and DavResourceKind from Forge in metadata.rs, replacing the local (EntityType, i64) tuple
  • Implement DavNamePolicy for SystemFileBlockPolicy to satisfy the Forge handler interface
  • Add AsterDavVersionProvider in version_provider.rs as a persistence adapter implementing aster_forge_webdav::deltav::DavVersionProvider
  • Implement open_download_stream and copy_dir_shallow on AsterDavFs to satisfy the updated DavFileSystem contract from Forge
  • Update all test imports (tests/webdav/) to reference types from aster_forge_webdav directly

Summary by CodeRabbit

  • 新功能

    • WebDAV 请求处理能力升级,支持更统一的文件访问、上传、复制及目录操作体验。
    • 新增文件版本历史查询与版本控制支持。
    • 增强大文件下载与分段传输表现。
  • 安全与稳定性

    • 改进 WebDAV 基础认证及错误提示。
    • 系统和受保护属性现不可被修改,避免敏感内容遭到意外变更。
    • 优化文件锁定、路径处理及并发访问行为。

- Remove local implementations of `DavPath`, `DavFileSystem`, `DavLockSystem`, and related traits from `src/webdav/dav.rs`; replace all imports with `aster_forge_webdav::dav`
- Delete in-tree WebDAV protocol modules (`props`, `protocol`, `responses`, `resources`, `locks`, `transfer`, `deltav`) and delegate the full protocol exchange to `aster_forge_webdav::handler::WebDavHandler`
- Add `aster_forge_webdav` dependency to `Cargo.toml`
- Replace local `is_system_namespace`, `is_dav_namespace`, and `is_protected_namespace` helpers in `property.rs` with imports from `aster_forge_webdav`
- Replace local `normalize_path`, `path_ancestors`, `lock_paths_overlap`, `lock_path_is_under`, and `unlock_request_targets_lock_scope` helpers in `db_lock_system.rs` with imports from `aster_forge_webdav::lock_paths`
- Replace local `parse_basic_authorization` / base64 decoding in `auth.rs` with `aster_forge_webdav::auth::parse_basic_authorization`
- Introduce `DavPropertyTarget` and `DavResourceKind` from Forge in `metadata.rs`, replacing the local `(EntityType, i64)` tuple
- Implement `DavNamePolicy` for `SystemFileBlockPolicy` to satisfy the Forge handler interface
- Add `AsterDavVersionProvider` in `version_provider.rs` as a persistence adapter implementing `aster_forge_webdav::deltav::DavVersionProvider`
- Implement `open_download_stream` and `copy_dir_shallow` on `AsterDavFs` to satisfy the updated `DavFileSystem` contract from Forge
- Update all test imports (`tests/webdav/`) to reference types from `aster_forge_webdav` directly
@AptS-1547 AptS-1547 self-assigned this Jul 24, 2026
@AptS-1547 AptS-1547 added Enhancement New feature or request Priority: Medium Medium priority issue Rust Pull requests that update Rust code labels Jul 24, 2026
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

本次变更引入 aster_forge_webdav,移除本地 WebDAV 协议、资源、锁和传输处理模块,改由统一 WebDavHandler 处理请求;认证、锁、属性、文件系统类型及 DeltaV 版本提供能力同步完成适配。

Changes

WebDAV 协议抽取与适配

Layer / File(s) Summary
外部契约与属性目标适配
Cargo.toml, src/services/content/property.rs, src/webdav/metadata.rs, src/webdav/system_file.rs
新增外部 WebDAV 依赖,使用 DavPropertyTarget、外部命名空间判断和 DavNamePolicy
统一处理器与版本控制接入
src/webdav/mod.rs, src/webdav/version_provider.rs, src/webdav/handler_tests/*
请求分发改为 WebDavHandler,新增 DeltaV 版本历史查询与版本控制路径校验。
文件系统流与属性接口适配
src/webdav/fs/*, src/webdav/dir_entry.rs, src/webdav/file/*, tests/webdav/file.rs
下载流改用 ReaderStream,属性目标签名迁移到外部类型,并实现浅层目录复制。
认证与锁路径实现迁移
src/webdav/auth.rs, src/webdav/db_lock_system.rs, src/webdav/path_resolver.rs, tests/webdav/lock_system.rs, tests/webdav/path_resolver.rs
Basic 认证解析及锁路径关系判断改用外部 crate,相关路径和测试类型同步迁移。
本地协议模块移除
src/webdav/dav.rs, src/webdav/deltav.rs, src/webdav/locks/*, src/webdav/protocol.rs, src/webdav/resources/*, src/webdav/responses.rs, src/webdav/transfer/*
删除本地 WebDAV 路径、协议解析、资源操作、锁、响应、传输和 DeltaV 实现。

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers: apts-1738

Poem

WebDAV 旧壳落成尘,
新 handler 接管门。
锁随路径迁远库,
流化春风过文件。
版本记录静静存。

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning 描述覆盖了主要改动,但未按仓库模板提供 Summary、Test plan 和 Notes for reviewers 等必填分区。 按模板补全 Summary、Test plan 勾选项和 Notes for reviewers,并注明数据库迁移、运行配置与升级说明。
Docstring Coverage ⚠️ Warning Docstring coverage is 26.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了将 WebDAV 协议逻辑迁移到 aster_forge_webdav 的主要变更。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/issue-428-webdav-crate

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedcargo/​aws-sdk-s3@​1.138.1 ⏵ 1.139.081100100100100
Updatedcargo/​russh@​0.62.3 ⏵ 0.62.49310093100100
Updatedcargo/​clap@​4.6.3 ⏵ 4.6.49910093100100
Updatedcargo/​tokio-util@​0.7.18 ⏵ 0.7.1910010093100100

View full report

@AptS-1547 AptS-1547 linked an issue Jul 24, 2026 that may be closed by this pull request
3 tasks

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/webdav/mod.rs (1)

70-71: 🚀 Performance & Scalability | 🔵 Trivial

版本历史是纯读路径,塞给 writer_db 有点浪费。

AsterDavVersionProvider 只做 PROPFIND/REPORT 的版本历史读取,属于允许短暂滞后的纯读路径;旁边 AsterDavFs::metadata 走的是 reader_db。这里用 writer_db 会把只读流量都压到主库上。规模上来后要疼的是你小子,不是我。若确无读后写一致性要求,建议改用 reader_db

依据 coding guidelines:「reader_db 仅用于允许短暂滞后的纯读路径」。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/webdav/mod.rs` around lines 70 - 71, Update the version_provider
initialization in the WebDAV request flow to pass state.get_ref().reader_db()
instead of writer_db(). Keep AsterDavVersionProvider::new and the surrounding
authentication flow unchanged, preserving this version-history read path as a
replica-eligible operation.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/webdav/fs/mod.rs`:
- Around line 401-419: 为 open_download_stream 和 copy_dir_shallow
补充单元或集成测试:验证文件全量读取、范围读取及底层读取失败时的错误映射;同时验证 copy_dir_shallow
成功复制目录内容,以及目标已存在时覆盖失败。复用现有普通下载和 range 测试的测试工具与断言方式,确保覆盖这两个方法对外暴露的新契约。
- Around line 690-692: 将 WebDAV 的 copy_dir_shallow 流程收敛到同一个 service/repository
写入边界,使用 writer transaction 统一编排目标删除、目录落库和属性迁移,确保任一步失败都回滚而不破坏旧目标。调整
AsterDavFs::copy_dir_shallow 及其调用的 folder::create_in_scope_with_audit,审计改为同一事务内的
outbox 或采用明确的失败处理策略。

---

Nitpick comments:
In `@src/webdav/mod.rs`:
- Around line 70-71: Update the version_provider initialization in the WebDAV
request flow to pass state.get_ref().reader_db() instead of writer_db(). Keep
AsterDavVersionProvider::new and the surrounding authentication flow unchanged,
preserving this version-history read path as a replica-eligible operation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f500c326-afeb-40b8-b5a2-59cbb94b9e5a

📥 Commits

Reviewing files that changed from the base of the PR and between 891b233 and 834c404.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (25)
  • Cargo.toml
  • src/services/content/property.rs
  • src/webdav/auth.rs
  • src/webdav/dav.rs
  • src/webdav/db_lock_system.rs
  • src/webdav/deltav.rs
  • src/webdav/dir_entry.rs
  • src/webdav/file/mod.rs
  • src/webdav/file/tests.rs
  • src/webdav/fs/mod.rs
  • src/webdav/handler_tests/mod.rs
  • src/webdav/locks/mod.rs
  • src/webdav/metadata.rs
  • src/webdav/mod.rs
  • src/webdav/path_resolver.rs
  • src/webdav/props/mod.rs
  • src/webdav/protocol.rs
  • src/webdav/resources/mod.rs
  • src/webdav/responses.rs
  • src/webdav/system_file.rs
  • src/webdav/transfer/mod.rs
  • src/webdav/version_provider.rs
  • tests/webdav/file.rs
  • tests/webdav/lock_system.rs
  • tests/webdav/path_resolver.rs
💤 Files with no reviewable changes (8)
  • src/webdav/props/mod.rs
  • src/webdav/locks/mod.rs
  • src/webdav/transfer/mod.rs
  • src/webdav/protocol.rs
  • src/webdav/resources/mod.rs
  • src/webdav/responses.rs
  • src/webdav/deltav.rs
  • src/webdav/dav.rs

Comment thread src/webdav/fs/mod.rs
Comment on lines +401 to +419
fn open_download_stream<'a>(
&'a self,
path: &'a DavPath,
offset: Option<u64>,
length: Option<u64>,
) -> FsFuture<'a, FsStream<Bytes>> {
Box::pin(async move {
let target = self
.resolve_download_target(path)
.await?
.ok_or(FsError::Forbidden)?;
let reader = self
.open_download_stream_for_file(&target.file, &target.blob, offset, length)
.await?;
let stream = ReaderStream::with_capacity(reader, DOWNLOAD_CHUNK_SIZE)
.map(|result| result.map_err(|_| FsError::GeneralFailure));
Ok(Box::pin(stream) as FsStream<Bytes>)
})
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 检查新增文件系统 trait 方法是否已有对应测试。
rg -nP -C3 '\b(open_download_stream|copy_dir_shallow)\s*\(' src tests
rg -nP -C3 '(range|offset|overwrite|shallow copy|download stream)' tests src/webdav

Repository: AsterCommunity/AsterDrive

Length of output: 50382


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Files mentioning new Forge filesystem trait methods:"
rg -n -C2 'open_download_stream|copy_dir_shallow|FsFileSystem|file_system' src/webdav tests \
  --glob '*.rs' || true

echo
echo "Outline of src/webdav/fs/mod.rs around trait and implementations:"
ast-grep outline src/webdav/fs/mod.rs --view compact 2>/dev/null || true
sed -n '1,240p' src/webdav/fs/mod.rs
echo "----"
sed -n '620,720p' src/webdav/fs/mod.rs

Repository: AsterCommunity/AsterDrive

Length of output: 12802


为 Forge 文件系统新增方法补齐测试。

当前只看到普通下载 / range 的现存测试覆盖,但 open_download_streamcopy_dir_shallow 的新契约缺少单元或集成测试:需要覆盖全量读取、范围读取、驱动读取失败,以及浅拷贝成功和覆盖失败的边界,否则外部 handler 容易回归。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/webdav/fs/mod.rs` around lines 401 - 419, 为 open_download_stream 和
copy_dir_shallow 补充单元或集成测试:验证文件全量读取、范围读取及底层读取失败时的错误映射;同时验证 copy_dir_shallow
成功复制目录内容,以及目标已存在时覆盖失败。复用现有普通下载和 range 测试的测试工具与断言方式,确保覆盖这两个方法对外暴露的新契约。

Source: Coding guidelines

Comment thread src/webdav/fs/mod.rs
Comment on lines +690 to +692
fn copy_dir_shallow<'a>(&'a self, from: &'a DavPath, to: &'a DavPath) -> FsFuture<'a, ()> {
Box::pin(async move { AsterDavFs::copy_dir_shallow(self, from, to).await })
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 定位浅复制调用链及覆盖删除、属性复制的边界。
ast-grep outline src/webdav/fs/mod.rs --items all --type function
rg -nP -C3 '\b(copy_dir_shallow|delete_existing_destination_for_overwrite|copy_visible_entity_properties)\s*\(' src tests

Repository: AsterCommunity/AsterDrive

Length of output: 6319


把 WebDAV 浅复制收敛为原子用例。

copy_dir_shallow 当前先在 copy_dir_shallow 里删除目标,再调用 folder::create_in_scope_with_audit 复制属性并记录 FolderCopy 审计;任一步失败都会让旧目标已丢、新对象不完整。把这组写操作放在同一个 service/repository 边界并用 writer transaction 编排,销毁/落库/属性迁移全部回滚;审计按 outbox 或明确策略处理。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/webdav/fs/mod.rs` around lines 690 - 692, 将 WebDAV 的 copy_dir_shallow
流程收敛到同一个 service/repository 写入边界,使用 writer transaction
统一编排目标删除、目录落库和属性迁移,确保任一步失败都回滚而不破坏旧目标。调整 AsterDavFs::copy_dir_shallow 及其调用的
folder::create_in_scope_with_audit,审计改为同一事务内的 outbox 或采用明确的失败处理策略。

Source: Coding guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request Priority: Medium Medium priority issue Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Extract WebDAV into a dedicated workspace crate

1 participant