Skip to content

Commit

Permalink
substudy: Create cache directory if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
emk committed Mar 30, 2024
1 parent 2e0f622 commit c862449
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions substudy/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
//! built for speed, because it's caching expensive AI requests that are made
//! over the network. Instead, we focus on reliability.
use std::{marker::PhantomData, path::PathBuf};
use std::{fs, marker::PhantomData, path::PathBuf};

use anyhow::Context as _;
use log::{debug, trace};
use log::{debug, trace, warn};
use rusqlite::Connection;
use serde::{de::DeserializeOwned, Serialize};

Expand Down Expand Up @@ -33,6 +33,14 @@ where
cache_name: &str,
approx_max_entries: u64,
) -> Result<Self> {
// Make sure our parent directory exists.
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
} else {
warn!("no parent directory for cache path");
}

// Set up the cache table.
let conn = Connection::open(&path)?;
conn.execute(
"CREATE TABLE IF NOT EXISTS substudy_cache (
Expand Down

0 comments on commit c862449

Please sign in to comment.