diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-11-26 14:34:15 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-11-26 14:34:15 +0800 |
| commit | 151d6be7e12288e4b03a8af331d89341e63b86d9 (patch) | |
| tree | 8513116dd1fde4cadd25db248367b389e8fea5c3 /src/bin | |
| parent | 4015ac6d594f971f83e9ff70578eb08fea390c80 (diff) | |
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.
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/jv.rs | 22 |
1 files changed, 22 insertions, 0 deletions
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 { |
