Added function to create file for database if one does not exist

This commit is contained in:
Emerson Rosen-Jones 2025-05-27 22:38:31 -04:00
parent ebbde2214a
commit aaa9d542b6

View file

@ -1,6 +1,8 @@
mod cli; mod cli;
mod db; mod db;
use std::{fs::File, path::Path};
use anyhow::anyhow; use anyhow::anyhow;
use clap::Parser; use clap::Parser;
use cli::Cli; use cli::Cli;
@ -16,6 +18,15 @@ async fn main() -> Result<()> {
Please provide one with the BOOKMARK_DB_PATH environment \ Please provide one with the BOOKMARK_DB_PATH environment \
variable.".to_string() variable.".to_string()
))?; ))?;
create_if_not_exists(&location)?;
let store = db::Store::new(&location, cli.is_reading_list).await?; let store = db::Store::new(&location, cli.is_reading_list).await?;
cli.run(store).await cli.run(store).await
} }
fn create_if_not_exists(path_string: &str) -> Result<()> {
let path = Path::new(path_string);
if !path.is_file() {
File::create(path)?;
}
Ok(())
}