From 151d6be7e12288e4b03a8af331d89341e63b86d9 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Wed, 26 Nov 2025 14:34:15 +0800 Subject: Preserve working directory during auto update The auto update process was changing the current working directory, which could cause issues when the program continues execution. This change saves the current directory before updating and restores it afterward, ensuring the program continues in the correct location. --- src/bin/jv.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/bin/jv.rs b/src/bin/jv.rs index ac6c5b1..0e874ca 100644 --- a/src/bin/jv.rs +++ b/src/bin/jv.rs @@ -642,11 +642,33 @@ async fn main() { // Auto update if enable_auto_update() && check_vault_modified().await { + // Record current directory + let path = match current_dir() { + Ok(path) => path, + Err(e) => { + eprintln!("{}", t!("jv.fail.get_current_dir", error = e.to_string())); + return; + } + }; + // Update + // This will change the current current_dir jv_update(UpdateArgs { help: false, silent: true, }) .await; + // Restore current directory + if let Err(e) = set_current_dir(&path) { + eprintln!( + "{}", + t!( + "jv.fail.std.set_current_dir", + dir = path.display(), + error = e + ) + ); + return; + } } let Ok(parser) = JustEnoughVcsWorkspace::try_parse() else { -- cgit