Files
zclaw_openfang/desktop/src-tauri/src/kernel_commands/workspace.rs
iven 5121a3c599
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
chore(desktop): Tauri 命令 @reserved 全量标注 — 88个无前端调用命令已标注
- 新增 66 个 @reserved 标注 (已有 22 个)
- 覆盖: agent/butler/classroom/hand/mcp/pipeline/skill/trigger/viking/zclaw 等模块
- MCP 命令增加 @connected 注释说明前端接入路径
- @reserved 总数: 89 (含 identity_init)
2026-04-15 02:05:58 +08:00

48 lines
1.2 KiB
Rust

//! Workspace directory statistics command
use serde::Serialize;
use std::path::Path;
#[derive(Serialize)]
pub struct DirStats {
pub file_count: u64,
pub total_size: u64,
}
/// Count files and total size in a directory (non-recursive, top-level only)
// @reserved: workspace statistics
#[tauri::command]
pub async fn workspace_dir_stats(path: String) -> Result<DirStats, String> {
let dir = Path::new(&path);
// Canonicalize to resolve '..' components and symlinks
let canonical = dir.canonicalize().unwrap_or_else(|_| dir.to_path_buf());
if !canonical.exists() {
return Ok(DirStats {
file_count: 0,
total_size: 0,
});
}
if !canonical.is_dir() {
return Err(format!("{} is not a directory", path));
}
let mut file_count: u64 = 0;
let mut total_size: u64 = 0;
let entries = std::fs::read_dir(&canonical).map_err(|e| format!("Failed to read dir: {}", e))?;
for entry in entries.flatten() {
if let Ok(metadata) = entry.metadata() {
if metadata.is_file() {
file_count += 1;
total_size += metadata.len();
}
}
}
Ok(DirStats {
file_count,
total_size,
})
}