fix: interpret --config flag properly

This commit is contained in:
Kiana Sheibani 2024-08-14 20:56:57 -04:00
parent 6460947ace
commit 221ba8268d
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
3 changed files with 5 additions and 6 deletions

View file

@ -22,9 +22,8 @@ pub struct DatasetMetadata {
}
/// Return the path to the datasets file.
fn datasets_path(config_dir: &Path) -> std::io::Result<PathBuf> {
let mut path = config_dir.to_owned();
path.push("startrnr");
fn datasets_path(dir: &Path) -> std::io::Result<PathBuf> {
let mut path = dir.to_owned();
// Create datasets path if it doesn't exist
fs::create_dir_all(&path)?;
@ -37,8 +36,8 @@ fn datasets_path(config_dir: &Path) -> std::io::Result<PathBuf> {
Ok(path)
}
pub fn open_datasets(config_dir: &Path) -> sqlite::Result<Connection> {
let path = datasets_path(config_dir).unwrap();
pub fn open_datasets(dir: &Path) -> sqlite::Result<Connection> {
let path = datasets_path(dir).unwrap();
let query = "
CREATE TABLE IF NOT EXISTS datasets (

View file

@ -113,6 +113,7 @@ fn main() {
let config_dir = cli
.config_dir
.map(|mut s| { s.push("startrnr"); s })
.unwrap_or_else(|| dirs::config_dir().expect("Could not determine config directory"));
let connection =
open_datasets(&config_dir).unwrap_or_else(|_| error("Could not open datasets file", 2));

View file

@ -28,7 +28,6 @@ pub fn get_auth_token(config_dir: &Path) -> String {
Err(VarError::NotUnicode(_)) => error("Invalid authorization key", 2),
Err(VarError::NotPresent) => {
let mut auth_file = config_dir.to_owned();
auth_file.push("startrnr");
auth_file.push("auth.txt");
read_to_string(auth_file)
.ok()