From 60d0a48a1ab11dfdc074b33c27fc93fce6bea0f2 Mon Sep 17 00:00:00 2001 From: DecDuck Date: Thu, 9 Jan 2025 12:27:32 +1100 Subject: [PATCH] fix(handle invalid database): use set_file_name instead of pushing to strings --- src-tauri/src/db.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src-tauri/src/db.rs b/src-tauri/src/db.rs index 647a377..4fcdb3d 100644 --- a/src-tauri/src/db.rs +++ b/src-tauri/src/db.rs @@ -1,10 +1,13 @@ use std::{ - collections::HashMap, fs::{self, create_dir_all}, path::{Path, PathBuf}, sync::{LazyLock, Mutex, RwLockWriteGuard} + collections::HashMap, + fs::{self, create_dir_all}, + path::{Path, PathBuf}, + sync::{LazyLock, Mutex, RwLockWriteGuard}, }; use chrono::Utc; use directories::BaseDirs; -use log::debug; +use log::{debug, info}; use rustbreak::{DeSerError, DeSerializer, PathDatabase, RustbreakError}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use serde_with::serde_as; @@ -12,7 +15,11 @@ use tauri::AppHandle; use url::Url; use crate::{ - download_manager::downloadable_metadata::DownloadableMetadata, games::{library::push_game_update, state::GameStatusManager}, process::process_manager::Platform, settings::Settings, DB + download_manager::downloadable_metadata::DownloadableMetadata, + games::{library::push_game_update, state::GameStatusManager}, + process::process_manager::Platform, + settings::Settings, + DB, }; #[derive(serde::Serialize, Clone, Deserialize)] @@ -70,7 +77,6 @@ pub struct DatabaseApplications { pub transient_statuses: HashMap, } - #[derive(Serialize, Deserialize, Clone, Default)] pub struct Database { #[serde(default)] @@ -237,13 +243,16 @@ fn handle_invalid_database( let new_path = { let time = Utc::now().timestamp(); let mut base = db_path.clone(); - base.push("."); - base.push(time.to_string()); + base.set_file_name(format!("drop.db.backup-{}", time.to_string())); base }; + info!("{:?}", new_path); fs::rename(&db_path, &new_path).unwrap(); - let db = Database ::new(games_base_dir.into_os_string().into_string().unwrap(), Some(new_path.into())); + let db = Database::new( + games_base_dir.into_os_string().into_string().unwrap(), + Some(new_path.into()), + ); PathDatabase::create_at_path(db_path, db).expect("Database could not be created") }