Skip to content

Commit

Permalink
Add cities DB to backup
Browse files Browse the repository at this point in the history
  • Loading branch information
MattBlack85 committed Mar 5, 2024
1 parent b766cfa commit b0cd1fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/backup/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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_full_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.finish() {
Ok(_) => (),
Err(e) => panic!("Couldn't create the archive, reason: {}", e),
Expand Down Expand Up @@ -93,6 +104,8 @@ pub fn retrieve_db(paths: &Paths, token: &String) -> Result<(), String> {
paths.indi_conf_full_path(),
&path.file_name().unwrap().to_str().unwrap()
);
} else if path.to_str().unwrap().contains(&"mycity") {
full_path = paths.city_db_full_path();
} else {
full_path = paths.db_full_path();
};
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct Paths {
logs_path: String,
pub home_path: String,
db_path: String,
city_db_path: String,
indi_conf_path: String,
}

Expand All @@ -43,6 +44,11 @@ impl Paths {
return db_path;
}

pub fn city_db_full_path(&self) -> String {
let db_path = format!("{}/{}", self.home_path, self.city_db_path);
return db_path;
}

pub fn indi_conf_full_path(&self) -> String {
let indi_conf_path = format!("{}/{}", self.home_path, self.indi_conf_path);
return indi_conf_path;
Expand All @@ -58,6 +64,7 @@ impl Paths {
#[cfg(target_os = "macos")]
db_path: String::from("Library/Application Support/kstars/userdb.sqlite"),
indi_conf_path: String::from(".indi/"),
city_db_path: String::from(".local/share/kstars/mycitydb.sqlite"),
}
}
}

0 comments on commit b0cd1fb

Please sign in to comment.