From 607f5959ab11f66707808506fed3bbf113ad8fe4 Mon Sep 17 00:00:00 2001 From: link2xt Date: Mon, 20 May 2024 17:27:53 +0000 Subject: [PATCH] fix: always convert absolute paths to relative in accounts.toml Even if the path does not start with the directory containing the config, we want to keep only the last component. --- src/accounts.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/accounts.rs b/src/accounts.rs index 233ad7968a..e6774fa989 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -485,10 +485,6 @@ impl Config { /// Read a configuration from the given file into memory. pub async fn from_file(file: PathBuf, writable: bool) -> Result { - let dir = file - .parent() - .context("Cannot get config file directory")? - .to_path_buf(); let mut config = Self::new_nosync(file, writable).await?; let bytes = fs::read(&config.file) .await @@ -500,9 +496,13 @@ impl Config { // Convert them to relative paths. let mut modified = false; for account in &mut config.inner.accounts { - if let Ok(new_dir) = account.dir.strip_prefix(&dir) { - account.dir = new_dir.to_path_buf(); - modified = true; + if account.dir.is_absolute() { + if let Some(old_path_parent) = account.dir.parent() { + if let Ok(new_path) = account.dir.strip_prefix(old_path_parent) { + account.dir = new_path.to_path_buf(); + modified = true; + } + } } } if modified && writable {