mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2026-06-22 04:11:37 +10:00
fix: database corrupted on every startup (#40)
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::{self, create_dir_all, File},
|
fs::{self, create_dir_all, File},
|
||||||
io::{self, ErrorKind, Read, Write},
|
io::{self, ErrorKind, Read, Write},
|
||||||
path::{Path, PathBuf}, thread::sleep, time::Duration,
|
path::{Path, PathBuf},
|
||||||
|
thread::sleep,
|
||||||
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
@@ -60,7 +62,6 @@ pub fn resolve(meta: &mut CloudSaveMetadata) -> File {
|
|||||||
file.id = Some(id);
|
file.id = Some(id);
|
||||||
}
|
}
|
||||||
let binding = serde_json::to_string(meta).unwrap();
|
let binding = serde_json::to_string(meta).unwrap();
|
||||||
println!("Binding: {}", &binding);
|
|
||||||
let serialized = binding.as_bytes();
|
let serialized = binding.as_bytes();
|
||||||
let mut file = tempfile().unwrap();
|
let mut file = tempfile().unwrap();
|
||||||
file.write(serialized).unwrap();
|
file.write(serialized).unwrap();
|
||||||
@@ -117,8 +118,10 @@ pub fn extract(file: PathBuf) -> Result<(), BackupError> {
|
|||||||
let new_path = parse_path(file.path.into(), handler, &manifest.game_version)?;
|
let new_path = parse_path(file.path.into(), handler, &manifest.game_version)?;
|
||||||
create_dir_all(&new_path.parent().unwrap()).unwrap();
|
create_dir_all(&new_path.parent().unwrap()).unwrap();
|
||||||
|
|
||||||
println!("Current path {:?} copying to {:?}", ¤t_path, &new_path);
|
println!(
|
||||||
|
"Current path {:?} copying to {:?}",
|
||||||
|
¤t_path, &new_path
|
||||||
|
);
|
||||||
|
|
||||||
copy_item(current_path, new_path).unwrap();
|
copy_item(current_path, new_path).unwrap();
|
||||||
}
|
}
|
||||||
@@ -168,7 +171,11 @@ fn copy_dir_recursive(src: &Path, dest: &Path) -> io::Result<()> {
|
|||||||
let metadata = entry.metadata()?;
|
let metadata = entry.metadata()?;
|
||||||
|
|
||||||
if metadata.is_file() {
|
if metadata.is_file() {
|
||||||
debug!("Writing file {} to {}", entry_path.display(), dest_entry_path.display());
|
debug!(
|
||||||
|
"Writing file {} to {}",
|
||||||
|
entry_path.display(),
|
||||||
|
dest_entry_path.display()
|
||||||
|
);
|
||||||
fs::copy(&entry_path, &dest_entry_path)?;
|
fs::copy(&entry_path, &dest_entry_path)?;
|
||||||
} else if metadata.is_dir() {
|
} else if metadata.is_dir() {
|
||||||
copy_dir_recursive(&entry_path, &dest_entry_path)?;
|
copy_dir_recursive(&entry_path, &dest_entry_path)?;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use log::{debug, error, info};
|
use log::{debug, error, info, warn};
|
||||||
use rustbreak::{DeSerError, DeSerializer, PathDatabase, RustbreakError};
|
use rustbreak::{DeSerError, DeSerializer, PathDatabase, RustbreakError};
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
@@ -99,6 +99,7 @@ fn handle_invalid_database(
|
|||||||
games_base_dir: PathBuf,
|
games_base_dir: PathBuf,
|
||||||
cache_dir: PathBuf,
|
cache_dir: PathBuf,
|
||||||
) -> rustbreak::Database<Database, rustbreak::backend::PathBackend, DropDatabaseSerializer> {
|
) -> rustbreak::Database<Database, rustbreak::backend::PathBackend, DropDatabaseSerializer> {
|
||||||
|
warn!("{}", _e);
|
||||||
let new_path = {
|
let new_path = {
|
||||||
let time = Utc::now().timestamp();
|
let time = Utc::now().timestamp();
|
||||||
let mut base = db_path.clone();
|
let mut base = db_path.clone();
|
||||||
|
|||||||
@@ -176,6 +176,7 @@ pub mod data {
|
|||||||
pub auth: Option<DatabaseAuth>,
|
pub auth: Option<DatabaseAuth>,
|
||||||
pub base_url: String,
|
pub base_url: String,
|
||||||
pub applications: DatabaseApplications,
|
pub applications: DatabaseApplications,
|
||||||
|
#[serde(skip)]
|
||||||
pub prev_database: Option<PathBuf>,
|
pub prev_database: Option<PathBuf>,
|
||||||
pub cache_dir: PathBuf,
|
pub cache_dir: PathBuf,
|
||||||
pub compat_info: Option<DatabaseCompatInfo>,
|
pub compat_info: Option<DatabaseCompatInfo>,
|
||||||
|
|||||||
Reference in New Issue
Block a user