Skip to content

Commit

Permalink
fix: always convert absolute paths to relative in accounts.toml
Browse files Browse the repository at this point in the history
Even if the path does not start with
the directory containing the config,
we want to keep only the last component.
  • Loading branch information
link2xt committed May 20, 2024
1 parent 11546a1 commit 607f595
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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
Expand All @@ -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 {
Expand Down

0 comments on commit 607f595

Please sign in to comment.