feat: add delete backup functionality with confirmation dialog

This commit is contained in:
Jason
2026-02-26 22:06:10 +08:00
parent 3590df68b8
commit 01cc766a05
9 changed files with 216 additions and 14 deletions
+6
View File
@@ -168,3 +168,9 @@ pub fn rename_db_backup(
) -> Result<String, String> {
Database::rename_backup(&oldFilename, &newName).map_err(|e| e.to_string())
}
/// Delete a database backup file
#[tauri::command]
pub fn delete_db_backup(filename: String) -> Result<(), String> {
Database::delete_backup(&filename).map_err(|e| e.to_string())
}
+25
View File
@@ -531,4 +531,29 @@ impl Database {
log::info!("Renamed backup: {old_filename} -> {new_filename}");
Ok(new_filename)
}
/// Delete a backup file permanently.
pub fn delete_backup(filename: &str) -> Result<(), AppError> {
// Validate filename (path traversal + .db suffix)
if filename.contains("..")
|| filename.contains('/')
|| filename.contains('\\')
|| !filename.ends_with(".db")
{
return Err(AppError::InvalidInput(
"Invalid backup filename".to_string(),
));
}
let backup_path = get_app_config_dir().join("backups").join(filename);
if !backup_path.exists() {
return Err(AppError::InvalidInput(format!(
"Backup file not found: {filename}"
)));
}
fs::remove_file(&backup_path).map_err(|e| AppError::io(&backup_path, e))?;
log::info!("Deleted backup: {filename}");
Ok(())
}
}
+2
View File
@@ -911,9 +911,11 @@ pub fn run() {
commands::save_file_dialog,
commands::open_file_dialog,
commands::open_zip_file_dialog,
commands::create_db_backup,
commands::list_db_backups,
commands::restore_db_backup,
commands::rename_db_backup,
commands::delete_db_backup,
commands::sync_current_providers_live,
// Deep link import
commands::parse_deeplink,