mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-07-22 07:06:43 +08:00
91 lines
2.0 KiB
Rust
91 lines
2.0 KiB
Rust
//! 备份管理接口
|
|
|
|
use async_trait::async_trait;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
/// 备份信息
|
|
#[derive(Debug, Clone)]
|
|
pub struct BackupInfo {
|
|
/// 备份ID
|
|
pub id: String,
|
|
/// 备份时间
|
|
pub timestamp: i64,
|
|
/// 备份路径
|
|
pub path: PathBuf,
|
|
/// 备份大小(字节)
|
|
pub size: u64,
|
|
/// 备份描述
|
|
pub description: String,
|
|
}
|
|
|
|
/// 备份管理器接口
|
|
///
|
|
/// 管理游戏客户端的备份和恢复
|
|
#[async_trait]
|
|
pub trait BackupManager: Send + Sync {
|
|
/// 创建备份
|
|
///
|
|
/// # 参数
|
|
///
|
|
/// - `source`: 源目录
|
|
/// - `description`: 备份描述
|
|
///
|
|
/// # 返回
|
|
///
|
|
/// - 成功:返回备份信息
|
|
/// - 失败:返回错误
|
|
async fn create_backup(&self, source: &Path, description: &str) -> Result<BackupInfo, String>;
|
|
|
|
/// 列出所有备份
|
|
///
|
|
/// # 返回
|
|
///
|
|
/// - 成功:返回备份列表
|
|
/// - 失败:返回错误
|
|
async fn list_backups(&self) -> Result<Vec<BackupInfo>, String>;
|
|
|
|
/// 恢复备份
|
|
///
|
|
/// # 参数
|
|
///
|
|
/// - `backup_id`: 备份ID
|
|
/// - `target`: 目标目录
|
|
///
|
|
/// # 返回
|
|
///
|
|
/// - 成功:返回 Ok(())
|
|
/// - 失败:返回错误
|
|
async fn restore_backup(&self, backup_id: &str, target: &Path) -> Result<(), String>;
|
|
|
|
/// 删除备份
|
|
///
|
|
/// # 参数
|
|
///
|
|
/// - `backup_id`: 备份ID
|
|
///
|
|
/// # 返回
|
|
///
|
|
/// - 成功:返回 Ok(())
|
|
/// - 失败:返回错误
|
|
async fn delete_backup(&self, backup_id: &str) -> Result<(), String>;
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_backup_info() {
|
|
let info = BackupInfo {
|
|
id: "backup_001".to_string(),
|
|
timestamp: 1234567890,
|
|
path: PathBuf::from("/backups/001"),
|
|
size: 1024,
|
|
description: "Test backup".to_string(),
|
|
};
|
|
|
|
assert_eq!(info.id, "backup_001");
|
|
assert_eq!(info.size, 1024);
|
|
}
|
|
}
|