mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
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.
This commit is contained in:
@@ -515,21 +515,21 @@ pub fn setup_localization(p: &str) -> Result<(), LocalizationError> {
|
||||
fn resolve_locales_dir_from_exe_dir(exe_dir: &Path, p: &str) -> Option<PathBuf> {
|
||||
// 1. <bindir>/locales/<prog>
|
||||
let coreutils = exe_dir.join("locales").join(p);
|
||||
if coreutils.exists() {
|
||||
if coreutils.is_dir() {
|
||||
return Some(coreutils);
|
||||
}
|
||||
|
||||
// 2. <prefix>/share/locales/<prog>
|
||||
if let Some(prefix) = exe_dir.parent() {
|
||||
let fhs = prefix.join("share").join("locales").join(p);
|
||||
if fhs.exists() {
|
||||
if fhs.is_dir() {
|
||||
return Some(fhs);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. <bindir>/<prog> (legacy fall-back)
|
||||
let fallback = exe_dir.join(p);
|
||||
if fallback.exists() {
|
||||
if fallback.is_dir() {
|
||||
return Some(fallback);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user