Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that paths are branded #1404

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/branding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ pub const BRANDING_WSL: &str = "EdgeDB.WSL.1";

/// The display name for the configuration file.
pub const CONFIG_FILE_DISPLAY_NAME: &str = "`gel.toml` (or `edgedb.toml`)";

/// The database/OS username.
// TODO: This should become "admin"
pub const BRANDING_USERNAME: &str = "edgedb";

/// The OS pathname for data files.
// TODO: Should this be "gel" as well?
// WARNING: This requires will require a migration strategy if we decide to change it
pub const BRANDING_PATH: &str = if cfg!(windows) { "EdgeDB" } else { "edgedb" };
18 changes: 9 additions & 9 deletions src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
use anyhow::Context;
use fn_error_context::context;

use crate::branding::BRANDING_CLI_CMD_FILE;
use crate::branding::{BRANDING_CLI_CMD_FILE, BRANDING_PATH};
use crate::cli::env::Env;

#[cfg(windows)]
Expand All @@ -28,12 +28,12 @@ pub fn cache_dir() -> anyhow::Result<PathBuf> {
let dir = if cfg!(windows) {
dirs::data_local_dir()
.context("cannot determine local data directory")?
.join("EdgeDB")
.join(BRANDING_PATH)
.join("cache")
} else {
dirs::cache_dir()
.context("cannot determine cache directory")?
.join("edgedb")
.join(BRANDING_PATH)
};
Ok(dir)
}
Expand All @@ -46,12 +46,12 @@ pub fn config_dir() -> anyhow::Result<PathBuf> {
let dir = if cfg!(windows) {
dirs::data_local_dir()
.context("cannot determine local data directory")?
.join("EdgeDB")
.join(BRANDING_PATH)
.join("config")
} else {
dirs::config_dir()
.context("cannot determine config directory")?
.join("edgedb")
.join(BRANDING_PATH)
};
Ok(dir)
}
Expand Down Expand Up @@ -128,7 +128,7 @@ pub fn binary_path() -> anyhow::Result<PathBuf> {
// windows and macos fit this branch
None => dirs::data_dir()
.context("cannot determine local data directory")?
.join("edgedb")
.join(BRANDING_PATH)
.join("bin"),
};
Ok(dir.join(BRANDING_CLI_CMD_FILE))
Expand All @@ -137,22 +137,22 @@ pub fn binary_path() -> anyhow::Result<PathBuf> {
pub fn data_dir() -> anyhow::Result<PathBuf> {
Ok(dirs::data_dir()
.ok_or_else(|| anyhow::anyhow!("Can't determine data directory"))?
.join("edgedb")
.join(BRANDING_PATH)
.join("data"))
}

pub fn portable_dir() -> anyhow::Result<PathBuf> {
Ok(dirs::data_dir()
.ok_or_else(|| anyhow::anyhow!("Can't determine data directory"))?
.join("edgedb")
.join(BRANDING_PATH)
.join("portable"))
}

#[cfg_attr(unix, allow(dead_code))]
pub fn wsl_dir() -> anyhow::Result<PathBuf> {
Ok(dirs::data_dir()
.ok_or_else(|| anyhow::anyhow!("Can't determine data directory"))?
.join("edgedb")
.join(BRANDING_PATH)
.join("wsl"))
}

Expand Down
2 changes: 1 addition & 1 deletion src/portable/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ pub struct Create {
#[arg(long, default_value = "edgedb")]
pub default_user: String,

/// The default branch name. This defaults to 'main' on EdgeDB >=5.x; otherwise
/// The default branch name. This defaults to 'main' on Gel/EdgeDB >=5.x; otherwise
/// 'edgedb' is used.
pub default_branch: Option<String>,

Expand Down
3 changes: 1 addition & 2 deletions src/portable/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ use url::Url;
use crate::async_util::timeout;
use crate::branding::{BRANDING, BRANDING_CLI};
use crate::cli::env::Env;
use crate::portable::windows;
use crate::portable::{platform, ver};
use crate::portable::{platform, ver, windows};
use crate::process::IntoArg;

pub const USER_AGENT: &str = BRANDING_CLI;
Expand Down
4 changes: 2 additions & 2 deletions src/portable/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use once_cell::sync::{Lazy, OnceCell};
use url::Url;

use crate::async_util;
use crate::branding::{BRANDING, BRANDING_CLI, BRANDING_WSL};
use crate::branding::{BRANDING, BRANDING_CLI, BRANDING_PATH, BRANDING_WSL};
use crate::bug;
use crate::cli::env::Env;
use crate::cli::upgrade::{self, self_version};
Expand Down Expand Up @@ -522,7 +522,7 @@ fn get_wsl_distro(install: bool) -> anyhow::Result<Wsl> {
),
)?;
} else {
let cache_path = download_dir.join("edgedb");
let cache_path = download_dir.join(BRANDING_PATH);
download_binary(&cache_path)?;
wsl_simple_cmd(
&wsl,
Expand Down
5 changes: 3 additions & 2 deletions src/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use rustyline::{Config, Context, Editor, Helper};
use tokio::sync::mpsc::Receiver;
use tokio::sync::oneshot::Sender;

use crate::branding::BRANDING_PATH;
use crate::commands::backslash;
use crate::completion;
use crate::highlight;
Expand Down Expand Up @@ -200,7 +201,7 @@ pub fn load_history<H: rustyline::Helper, I: History>(
name: &str,
) -> Result<(), anyhow::Error> {
let dir = data_local_dir().context("cannot find local data dir")?;
let app_dir = dir.join("edgedb");
let app_dir = dir.join(BRANDING_PATH);
match ed.load_history(&app_dir.join(format!("{name}.history"))) {
Err(ReadlineError::Io(e)) if e.kind() == ErrorKind::NotFound => {}
Err(e) => return Err(e).context("error loading history")?,
Expand All @@ -214,7 +215,7 @@ fn _save_history<H: Helper, I: History>(
name: &str,
) -> Result<(), anyhow::Error> {
let dir = data_local_dir().context("cannot find local data dir")?;
let app_dir = dir.join("edgedb");
let app_dir = dir.join(BRANDING_PATH);
if !app_dir.exists() {
fs::create_dir_all(&app_dir).context("cannot create application dir")?;
}
Expand Down
Loading