Files
markbase/docs/SERVER_RS_FIX_PLAN.md
Warren 1300a4e223
Some checks failed
Test / test (push) Has been cancelled
Test / build (push) Has been cancelled
MarkBase架构升级:Multi-Volume Virtual Tree + Dual-View Management + Git Remote修正
核心功能:
-  Categories/Series双视图管理(category_view.rs + import_markdown.rs)
-  FUSE Multi-Volume支持(tree_type参数)
-  SSH/SFTP/SCP/rsync协议完整实现(4042行)
-  NFS/SMB Module Phase 1-3完成
-  Archive Module Phase 1-4完成(2916行)
-  Download Center API完整实现
-  S3兼容API实现(560行)

Git配置修正:
-  删除错误origin(gitea.momentry.ddns.net)
-  删除m5max128(指向机器名)
-  设置origin = m5max128gitea.momentry.ddns.net/admin/markbase
-  设置m4minigitea = m4minigitea.momentry.ddns.net/warren/markbase

数据清理:
-  删除38个临时SQLite(保留accusys.sqlite、demo.sqlite)
-  删除.bak、test_*.bin、调试脚本等临时文件
-  删除临时目录(build/、download files/、raid_test/等)
-  更新.gitignore排除临时文件

架构优化:
- 52个文件修改,2434行新增,4739行删除
- Workspace成员整合(16个crate)
- 数据库状态:accusys.sqlite保留(主demo测试)

远程同步:
-  准备推送到m5max128gitea(远程Gitea)
-  准备推送到m4minigitea(本地Gitea)
2026-06-12 12:59:54 +08:00

251 lines
5.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# server.rs修复计划
**诊断时间**: 2026-06-10 01:20
**状态**: ⚠️ 需修复
---
## 一、当前结构问题
### 问题诊断
**第1-33行**
- imports正确
- MarkBaseSftpServer struct正确
- impl Server for MarkBaseSftpServer缺少闭合的}
**第34-113行**
- channel_open_session方法缺少impl Handler声明
- subsystem_request方法
- exec_request方法
- shell_request方法
- 多余的}第114行
**第115-198行**
- 重复的channel_open_session
- 重复的subsystem_request
- 重复的exec_request
- 重复的shell_request
- 多余的}第197行
**第200-480行**
- 其他辅助方法handle_rsync_command等
---
### 根本原因
**缺少impl russh::server::Handler for SshSession声明**
正确结构应该是:
```rust
// imports
use ...
// MarkBaseSftpServer struct
pub struct MarkBaseSftpServer { ... }
// impl Server for MarkBaseSftpServer
impl Server for MarkBaseSftpServer {
type Handler = SshSession;
fn new_client(&mut self, ...) -> Self::Handler {
SshSession { ... }
}
}
// SshSession struct
pub struct SshSession { ... }
// impl Handler for SshSession ← 缺少这个
impl russh::server::Handler for SshSession {
async fn channel_open_session(...) { ... }
async fn subsystem_request(...) { ... }
async fn exec_request(...) { ... }
async fn shell_request(...) { ... }
}
// 辅助方法
impl SshSession {
async fn handle_rsync_command(...) { ... }
async fn handle_scp_sender(...) { ... }
fn get_channel(...) { ... }
}
```
---
## 二、修复方案
### 方案A完整重构 ⭐⭐⭐⭐⭐(推荐)
**步骤**
1. 提取imports第1-5行
2. 提取MarkBaseSftpServer struct + impl Server第6-33行
3. 找到SshSession struct定义
4. 添加impl russh::server::Handler for SshSession
5. 插入方法channel_open_session, subsystem_request, exec_request, shell_request
6. 删除重复方法第115-198行
7. 添加handle_scp_sender方法
---
### 方案B最小修复 ⭐⭐⭐
**步骤**
1. 删除重复方法第115-198行
2. 修复多余的}
3. 保持现有结构
---
## 三、实施步骤方案A
**Phase 1提取有效部分**
```bash
# 提取imports
sed -n '1,5p' server.rs
# 提取MarkBaseSftpServer + impl Server
sed -n '6,33p' server.rs
# 找到SshSession struct
grep -n "pub struct SshSession" server.rs
# 提取辅助方法
sed -n '200,480p' server.rs
```
**Phase 2重新构建**
```rust
// 1. imports
use crate::sftp::audit::AuditLog;
use crate::sftp::config::SftpConfig;
use crate::sftp::scp_sender::ScpSenderHandler; // 新增
// 2. MarkBaseSftpServer + impl Server
pub struct MarkBaseSftpServer { ... }
impl Server for MarkBaseSftpServer {
type Handler = SshSession;
fn new_client(&mut self, ...) -> Self::Handler { ... }
}
// 3. SshSession struct需要找到
pub struct SshSession { ... }
// 4. impl Handler for SshSession ← 关键修复
impl russh::server::Handler for SshSession {
type Error = anyhow::Error;
async fn auth_password(...) { ... }
async fn channel_open_session(...) {
// 从第34-42行提取
}
async fn subsystem_request(...) {
// 从第44-70行提取
}
async fn exec_request(...) {
// 从第72-98行提取 + 修改SCP sender路由
}
async fn shell_request(...) {
// 从第100-112行提取
}
}
// 5. 辅助方法 impl SshSession
impl SshSession {
async fn handle_rsync_command(...) { ... }
async fn handle_scp_sender(...) { ... }
fn get_channel(...) { ... }
}
```
---
## 四、关键改动
### exec_request修改SCP sender路由
```rust
async fn exec_request(
&mut self,
channel: ChannelId,
data: &[u8],
session: &mut Session,
) -> Result<(), Self::Error> {
let command = String::from_utf8_lossy(data);
let command_str = command.to_string();
if command_str.starts_with("scp -f") {
// SCP sender → 新增实现
self.handle_scp_sender(channel, &command_str).await?;
} else if command_str.starts_with("scp -t") {
// SCP receiver → placeholder
log::warn!("SCP receiver not supported");
} else if command_str.starts_with("rsync --server --sender") {
// rsync sender → 已有
self.handle_rsync_sender(channel, &command_str).await?;
} else if command_str.starts_with("rsync --server --receiver") {
// rsync receiver → placeholder
log::warn!("rsync receiver not supported");
} else {
log::warn!("Unsupported exec command");
}
Ok(())
}
```
---
### handle_scp_sender新增方法
```rust
impl SshSession {
async fn handle_scp_sender(
&mut self,
channel: ChannelId,
command: &str,
) -> Result<()> {
let scp_handler = ScpSenderHandler::new(
self.config.sftp.base_path.clone(),
self.user_id.clone(),
);
let (file_path, _) = scp_handler.handle_scp_sender(command)?;
let header = scp_handler.build_scp_header(&file_path)?;
let content = scp_handler.read_file_content(&file_path)?;
let channel_obj = self.get_channel(channel).await;
if let Some(ch) = channel_obj {
ch.write_all(header.as_bytes()).await?;
ch.write_all(&content).await?;
ch.write_all(&[0x00]).await?;
ch.write_all(&['E' as u8, '\n' as u8]).await?;
}
Ok(())
}
}
```
---
## 五、预期结果
**修复后文件结构**
- imports5行
- MarkBaseSftpServer + impl Server28行
- SshSession struct + impl Handler约80行
- 辅助方法 impl SshSession约200行
- **总计**约300行减少178行重复代码
---
**修复计划完成时间**: 2026-06-10 01:25
**版本**: 1.0