Skip to content

Commit

Permalink
Make stash path function public (#358)
Browse files Browse the repository at this point in the history
Trying to reduce duplication between CLI/driver. Also, prevent caller error by forcing this function to canonincalize internally.
  • Loading branch information
mmastrac authored Nov 4, 2024
1 parent 7fd932b commit c545576
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 9 additions & 8 deletions edgedb-tokio/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,12 @@ fn default_runtime_base() -> Result<PathBuf, Error> {
))
}

fn stash_path(project_dir: &Path) -> Result<PathBuf, Error> {
Ok(config_dir()?.join("projects").join(stash_name(project_dir)))
/// Compute the path to the project's stash file based on the canonical path.
pub fn get_stash_path(project_dir: &Path) -> Result<PathBuf, Error> {
let canonical = project_dir.canonicalize().map_err(|e| {
ClientError::with_source(e).context("project directory could not be canonicalized")
})?;
Ok(config_dir()?.join("projects").join(stash_name(&canonical)))
}

fn is_valid_local_instance_name(name: &str) -> bool {
Expand Down Expand Up @@ -1460,13 +1464,10 @@ impl Builder {
};
let dir = dir
.parent()
.ok_or_else(|| ClientError::with_message("Project directory has no parent"))?;
let canon = fs::canonicalize(&dir).await.map_err(|e| {
ClientError::with_source(e).context(format!("failed to canonicalize dir {:?}", dir))
})?;
let stash_path = stash_path(canon.as_ref())?;
.ok_or_else(|| ClientError::with_message("Project file has no parent"))?;
let stash_path = get_stash_path(dir)?;
if fs::metadata(&stash_path).await.is_ok() {
return Ok(Some((canon, stash_path)));
return Ok(Some((dir.to_owned(), stash_path)));
}
Ok(None)
}
Expand Down
5 changes: 4 additions & 1 deletion edgedb-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,11 @@ pub use transaction::Transaction;
/// The ordered list of project filenames supported.
pub const PROJECT_FILES: &[&str] = &["gel.toml", "edgedb.toml"];

/// The default project filename.
pub const DEFAULT_PROJECT_FILE: &str = PROJECT_FILES[0];

#[cfg(feature = "unstable")]
pub use builder::get_project_path;
pub use builder::{get_project_path, get_stash_path};

/// Create a connection to the database with default parameters
///
Expand Down

0 comments on commit c545576

Please sign in to comment.