Skip to content

Commit

Permalink
Make cache dir configurable
Browse files Browse the repository at this point in the history
(cherry picked from commit a8760bc)
  • Loading branch information
titanous authored and olexiyb committed Jun 13, 2024
1 parent 8f9b3e8 commit 5c53c51
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/pg_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ impl PgAccess {
pub async fn new(
fetch_settings: &PgFetchSettings,
database_dir: &PathBuf,
cache_dir: Option<&PathBuf>,
) -> Result<Self, PgEmbedError> {
// cache directory
let cache_dir = Self::create_cache_dir_structure(&fetch_settings).await?;
let cache_dir = match cache_dir {
Some(d) => d.clone(),
None => Self::create_cache_dir_structure(&fetch_settings).await?,
};

Self::create_db_dir_structure(database_dir).await?;
// pg_ctl executable
let mut pg_ctl = cache_dir.clone();
Expand Down
9 changes: 8 additions & 1 deletion src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ use crate::pg_types::PgResult;
pub struct PgSettings {
/// postgresql database directory
pub database_dir: PathBuf,
// cache directory
pub cache_dir: Option<PathBuf>,
/// postgresql port
pub port: u16,
/// postgresql user name
Expand Down Expand Up @@ -100,7 +102,12 @@ impl PgEmbed {
&password,
pg_settings.port.to_string()
);
let pg_access = PgAccess::new(&fetch_settings, &pg_settings.database_dir).await?;
let pg_access = PgAccess::new(
&fetch_settings,
&pg_settings.database_dir,
pg_settings.cache_dir.as_ref(),
)
.await?;
Ok(PgEmbed {
pg_settings,
fetch_settings,
Expand Down

0 comments on commit 5c53c51

Please sign in to comment.