From 830e80622edab80670d9c72097a15ca295fb5207 Mon Sep 17 00:00:00 2001 From: Breadway Date: Fri, 17 Jul 2026 10:13:06 +0800 Subject: [PATCH] Fix literal-tilde fallback bug in breadarr-shared's expand_home MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit expand_home() fell through to PathBuf::from(input) — the literal, unexpanded "~/..." string — whenever the HOME env var itself wasn't set, same bug class as breadclip-core/breadpad-shared/breadmon (found during this pass's own crate-migration sweep, in a different shape here: the bug was in this crate's own tilde-expansion helper rather than a dirs::xxx().unwrap_or_else() chain). Fixed via bread_utils::xdg::home_dir, which resolves a real home directory before ever needing to fall back. Builds and tests clean: 205 passed, 1 pre-existing network-dependent test ignored, 0 failed. --- Cargo.lock | 1 + breadarr-shared/Cargo.toml | 2 ++ breadarr-shared/src/config.rs | 12 +++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d8cee0c..0ab0e3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -203,6 +203,7 @@ name = "breadarr-shared" version = "0.1.0" dependencies = [ "anyhow", + "bread-utils", "chrono", "reqwest", "serde", diff --git a/breadarr-shared/Cargo.toml b/breadarr-shared/Cargo.toml index 0018ea6..5900351 100644 --- a/breadarr-shared/Cargo.toml +++ b/breadarr-shared/Cargo.toml @@ -9,3 +9,5 @@ anyhow.workspace = true toml.workspace = true reqwest.workspace = true chrono.workspace = true +# TODO(owner): switch to tag-pinned git dependency once bread-utils is merged and tagged, matching the bread-theme pattern +bread-utils = { path = "../../bread-ecosystem-fix-worktree/bread-utils" } diff --git a/breadarr-shared/src/config.rs b/breadarr-shared/src/config.rs index 64e47b6..1a9928b 100644 --- a/breadarr-shared/src/config.rs +++ b/breadarr-shared/src/config.rs @@ -314,10 +314,16 @@ fn config_path() -> PathBuf { } fn expand_home(input: &str) -> PathBuf { + // Was: falls through to `PathBuf::from(input)` — a literal, unexpanded + // "~/..." string — whenever the `HOME` env var itself isn't set. + // PathBuf/std::fs never expand `~`, so that fallback silently produced + // a path relative to the current working directory instead of the + // user's actual home. Same bug class as breadclip-core/breadpad-shared/ + // breadmon (see bread_utils::xdg's doc comment); bread_utils::xdg::home_dir + // resolves a real home directory (falling back to `/root`, never a + // literal tilde) before this ever needs to fall back at all. if let Some(stripped) = input.strip_prefix("~/") { - if let Ok(home) = env::var("HOME") { - return Path::new(&home).join(stripped); - } + return bread_utils::xdg::home_dir().join(stripped); } PathBuf::from(input) }