Moved the db

This commit is contained in:
Connor Johnstone
2026-03-03 13:10:37 -05:00
parent ba094a5dc5
commit f5f0273853
3 changed files with 23 additions and 10 deletions

View File

@@ -7,11 +7,23 @@ mod tui;
use std::collections::HashMap;
use std::env;
use std::path::Path;
use std::path::{Path, PathBuf};
use rand::distr::weighted::WeightedIndex;
use rand::prelude::*;
fn db_path() -> PathBuf {
let data_dir = env::var("XDG_DATA_HOME")
.map(PathBuf::from)
.unwrap_or_else(|_| {
let home = env::var("HOME").expect("HOME not set");
PathBuf::from(home).join(".local/share")
});
let dir = data_dir.join("playlists");
std::fs::create_dir_all(&dir).expect("failed to create data directory");
dir.join("playlists.db")
}
fn usage(program: &str) -> ! {
eprintln!("Usage:");
eprintln!(" {program} index [-v] <directory>");
@@ -50,7 +62,7 @@ fn cmd_index(args: &[String]) {
std::process::exit(1);
}
let conn = db::open("playlists.db").expect("failed to open database");
let conn = db::open(&db_path()).expect("failed to open database");
let lastfm = lastfm::LastfmClient::new(api_key);
let dir = Path::new(rest[0].as_str());
@@ -166,7 +178,7 @@ fn cmd_build(args: &[String]) {
}
dotenvy::dotenv().ok();
let conn = db::open("playlists.db").expect("failed to open database");
let conn = db::open(&db_path()).expect("failed to open database");
let (artist_mbid, seed_name) = if let Some(file_arg) = rest.first() {
let path = Path::new(file_arg.as_str());