From 6e8769c768990c72678de0f6fe092030474ccbcf Mon Sep 17 00:00:00 2001 From: rami3l Date: Wed, 13 Mar 2024 11:42:12 +0800 Subject: [PATCH] fix(shell): create parent dir before appending to rcfiles --- src/cli/self_update/unix.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cli/self_update/unix.rs b/src/cli/self_update/unix.rs index 7bf169453d..4e99c48e46 100644 --- a/src/cli/self_update/unix.rs +++ b/src/cli/self_update/unix.rs @@ -92,6 +92,13 @@ pub(crate) fn do_add_to_path() -> Result<()> { _ => &source_cmd, }; + let rc_dir = rc.parent().with_context(|| { + format!( + "parent directory doesn't exist for rcfile path: `{}`", + rc.display() + ) + })?; + utils::ensure_dir_exists("rcfile dir", rc_dir, &|_: Notification<'_>| ())?; utils::append_file("rcfile", &rc, cmd_to_write) .with_context(|| format!("could not amend shell profile: '{}'", rc.display()))?; }