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

fix(cli): canonicalize keystore path #19312

Merged
merged 2 commits into from
Sep 11, 2024
Merged
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
26 changes: 21 additions & 5 deletions crates/sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::fire_drill::{run_fire_drill, FireDrill};
use crate::genesis_ceremony::{run, Ceremony};
use crate::keytool::KeyToolCommand;
use crate::validator_commands::SuiValidatorCommand;
use anyhow::{anyhow, bail, ensure};
use anyhow::{anyhow, bail, ensure, Context};
use clap::*;
use fastcrypto::traits::KeyPair;
use move_analyzer::analyzer;
Expand Down Expand Up @@ -1138,10 +1138,26 @@ async fn prompt_if_no_config(
};

if let Some(env) = env {
let keystore_path = wallet_conf_path
.parent()
.unwrap_or(&sui_config_dir()?)
.join(SUI_KEYSTORE_FILENAME);
let keystore_path = match wallet_conf_path.parent() {
// Wallet config was created in the current directory as a relative path.
Some(parent) if parent.as_os_str().is_empty() => {
std::env::current_dir().context("Couldn't find current directory")?
}

// Wallet config was given a path with some parent (could be relative or absolute).
Some(parent) => parent
.canonicalize()
.context("Could not find sui config directory")?,

// No parent component and the wallet config was the empty string, use the default
// config.
None if wallet_conf_path.as_os_str().is_empty() => sui_config_dir()?,

// Wallet config was requested at the root of the file system ...for some reason.
None => wallet_conf_path.to_owned(),
}
.join(SUI_KEYSTORE_FILENAME);

let mut keystore = Keystore::from(FileBasedKeystore::new(&keystore_path)?);
let key_scheme = if accept_defaults {
SignatureScheme::ED25519
Expand Down
Loading