From 9526057afa0f1581f29af1f94f4c3bccd0943887 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Thu, 6 Jan 2022 11:40:59 +0200 Subject: [PATCH] Create the multishells directory if it is missing (#626) --- src/commands/use.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/commands/use.rs b/src/commands/use.rs index 6f53421..f66096f 100644 --- a/src/commands/use.rs +++ b/src/commands/use.rs @@ -93,6 +93,14 @@ impl Command for Use { outln!(config, Info, "{}", message); } + if let Some(multishells_path) = multishell_path.parent() { + std::fs::create_dir_all(multishells_path).map_err(|_err| { + Error::MultishellDirectoryCreationIssue { + path: multishells_path.to_path_buf(), + } + })?; + } + replace_symlink(&version_path, multishell_path).context(SymlinkingCreationIssue)?; Ok(()) @@ -220,6 +228,8 @@ pub enum Error { "Check out our documentation for more information: https://fnm.vercel.app" ))] FnmEnvWasNotSourced, + #[snafu(display("Can't create the multishell directory: {}", path.display()))] + MultishellDirectoryCreationIssue { path: std::path::PathBuf }, } #[derive(Debug, Snafu)]