diff --git a/crates/sui/src/sui_commands.rs b/crates/sui/src/sui_commands.rs index 569007d9c2d5e..3838d00f22da4 100644 --- a/crates/sui/src/sui_commands.rs +++ b/crates/sui/src/sui_commands.rs @@ -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; @@ -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