Skip to content

Commit 4c32ebc

Browse files
authored
fix(uucore): use is_dir() instead of exists() for locale path resolution (#11851)
In release builds, resolve_locales_dir_from_exe_dir() used .exists() to check for locale directories, which matches regular files (e.g. binaries) too. When an individual utility binary like `target/release/wc` exists alongside the multicall `coreutils` binary, the function incorrectly treats it as a locale directory. This causes setup_localization() to call init_localization() with a wrong path, leading to a FluentBundle that may lack utility-specific messages. The translate!() macro then returns the raw Fluent key instead of the resolved message. Observed in Debian builds where coreutils 0.8.0 is installed on the host during the build, causing test_files0_stops_after_stdout_write_error to fail because "wc-error-failed-to-print-result" is emitted verbatim instead of "failed to print result for /dev/null". Fix: use .is_dir() so only actual directories are accepted as locale paths, allowing the embedded locale fallback to work correctly.
1 parent 6995eb7 commit 4c32ebc

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/uucore/src/lib/mods/locale.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,21 +515,21 @@ pub fn setup_localization(p: &str) -> Result<(), LocalizationError> {
515515
fn resolve_locales_dir_from_exe_dir(exe_dir: &Path, p: &str) -> Option<PathBuf> {
516516
// 1. <bindir>/locales/<prog>
517517
let coreutils = exe_dir.join("locales").join(p);
518-
if coreutils.exists() {
518+
if coreutils.is_dir() {
519519
return Some(coreutils);
520520
}
521521

522522
// 2. <prefix>/share/locales/<prog>
523523
if let Some(prefix) = exe_dir.parent() {
524524
let fhs = prefix.join("share").join("locales").join(p);
525-
if fhs.exists() {
525+
if fhs.is_dir() {
526526
return Some(fhs);
527527
}
528528
}
529529

530530
// 3. <bindir>/<prog> (legacy fall-back)
531531
let fallback = exe_dir.join(p);
532-
if fallback.exists() {
532+
if fallback.is_dir() {
533533
return Some(fallback);
534534
}
535535

0 commit comments

Comments
 (0)