Skip to content

Commit

Permalink
Stop checking for SQLite db file when using Postgres in vit-ss server…
Browse files Browse the repository at this point in the history
… and vit-ss CLI (#90)
  • Loading branch information
minikin committed Nov 25, 2022
2 parents 052dc58 + a5904a4 commit f2be547
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Expand Up @@ -122,13 +122,16 @@ impl ApiTokenCmd {
}
}

fn handle_api_token_add_whith_db_backup(
fn handle_api_token_add_with_db_backup(
tokens: &Option<Vec<String>>,
db_url: &str,
) -> Result<(), Error> {
let backup_file = backup_db_file(db_url)?;
if let Err(e) = Self::handle_api_token_add(tokens, db_url) {
restore_db_file(backup_file, db_url)?;
if !db_url.starts_with("postgres://") {
let backup_file = backup_db_file(db_url)?;
restore_db_file(backup_file, db_url)?;
}

Err(e)
} else {
Ok(())
Expand All @@ -150,7 +153,7 @@ impl ExecTask for ApiTokenCmd {
fn exec(&self) -> Result<(), Error> {
match self {
ApiTokenCmd::Add { tokens, db_url } => {
ApiTokenCmd::handle_api_token_add_whith_db_backup(tokens, db_url)
ApiTokenCmd::handle_api_token_add_with_db_backup(tokens, db_url)
}
ApiTokenCmd::Generate { n, size } => {
ApiTokenCmd::handle_generate(*n, *size);
Expand Down
Expand Up @@ -4,10 +4,10 @@ use std::io::{Read, Write};

pub fn db_file_exists(db_url: &str) -> io::Result<()> {
// check if db file exists
if !std::path::Path::new(db_url).exists() {
if !db_url.starts_with("postgres://") && !std::path::Path::new(db_url).exists() {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("{} url does not exists", db_url),
format!("DB file does not exist: {}", db_url),
));
}
Ok(())
Expand Down
Expand Up @@ -171,7 +171,9 @@ async fn main() -> ApplicationExitCode {
};

// Check db file exists (should be here only for current sqlite db backend)
if !std::path::Path::new(&settings.db_url).exists() {
if !settings.db_url.starts_with("postgres://")
&& !std::path::Path::new(&settings.db_url).exists()
{
error!("DB file {} not found.", &settings.db_url);
return ApplicationExitCode::DbConnectionError;
}
Expand Down

0 comments on commit f2be547

Please sign in to comment.