Files
markbase/markbase-core/src/cli/storage/sync.rs
T
Warren d94cb2df4c Fix code quality: trailing whitespace, unused imports, clippy warnings
- Fix trailing whitespace in kex.rs and s3.rs
- Add missing KexProposal import in kex_complete.rs
- Auto-fix clippy warnings across all crates
- All 153 tests pass
2026-06-19 05:21:38 +08:00

67 lines
2.1 KiB
Rust

use clap::Subcommand;
#[derive(Subcommand)]
pub enum SyncCommand {
#[command(name = "sync-start")]
Start {
#[arg(short, long)]
source: String,
#[arg(short, long)]
target: String,
#[arg(short, long, default_value = "mirror")]
mode: String,
},
#[command(name = "sync-status")]
Status,
}
pub fn handle_sync_command(cmd: SyncCommand) -> anyhow::Result<()> {
match cmd {
SyncCommand::Start {
source,
target,
mode,
} => {
use std::path::Path;
println!("Syncing {} to {} (mode: {})", source, target, mode);
let source_path = Path::new(&source);
let target_path = Path::new(&target);
if !source_path.exists() {
return Err(anyhow::anyhow!("Source path not found: {}", source));
}
if mode == "mirror" {
std::fs::create_dir_all(target_path)?;
let entries = std::fs::read_dir(source_path)?;
for entry in entries {
let entry = entry?;
let path = entry.path();
let target_file = target_path.join(entry.file_name());
if path.is_file() {
std::fs::copy(&path, &target_file)?;
println!(" Copied: {:?}", entry.file_name());
} else if path.is_dir() {
std::fs::create_dir_all(&target_file)?;
println!(" Created directory: {:?}", entry.file_name());
}
}
println!("✓ Sync completed (mirror mode)");
} else {
return Err(anyhow::anyhow!("Unknown sync mode: {}. Use 'mirror'", mode));
}
}
SyncCommand::Status => {
println!("Checking sync status");
println!("Note: Sync status tracking requires persistent state management.");
println!("Current implementation: Simple directory sync without state tracking.");
}
}
Ok(())
}