Skip to content

Commit

Permalink
Check mycity DB exists before attempting a backup
Browse files Browse the repository at this point in the history
  • Loading branch information
MattBlack85 committed Mar 8, 2024
1 parent 1de4005 commit baeb790
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/backup/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ use log::info;
use minreq;
use std::fs::File;
use std::io::{Read, Write};
use std::path::Path;
use tar::{Archive, Builder};

fn check_city_db_exists(paths: &Paths) -> bool {
Path::new(&paths.city_db_path).exists()
}

pub fn send_db(paths: &Paths, token: &String) -> Result<(), String> {
// Init the zip archive
let file = match File::create("/tmp/k_backup.tar") {
Expand All @@ -31,15 +36,17 @@ pub fn send_db(paths: &Paths, token: &String) -> Result<(), String> {
Err(e) => panic!("Couldn't append the database to the archive, reason: {}", e),
}

// Add city database to the archive
let mut city_db = match File::open(&paths.city_db_path) {
Ok(f) => f,
Err(e) => panic!("Couldn't open the Kstars city database, reason: {}", e),
};
if check_city_db_exists(paths) {
// Add city database to the archive
let mut city_db = match File::open(&paths.city_db_path) {
Ok(f) => f,
Err(e) => panic!("Couldn't open the Kstars city database, reason: {}", e),
};

match arch.append_file("backup/kstars/mycitydb.sqlite", &mut city_db) {
Ok(_) => (),
Err(e) => panic!("Couldn't append the database to the archive, reason: {}", e),
match arch.append_file("backup/kstars/mycitydb.sqlite", &mut city_db) {
Ok(_) => (),
Err(e) => panic!("Couldn't append the database to the archive, reason: {}", e),
}
}

// Add fov.dat to the archive
Expand Down

0 comments on commit baeb790

Please sign in to comment.