Skip to content

fix(uucore): use is_dir() instead of exists() for locale path resolution#11851

Open
mattsu2020 wants to merge 2 commits intouutils:mainfrom
mattsu2020:locale_fix
Open

fix(uucore): use is_dir() instead of exists() for locale path resolution#11851
mattsu2020 wants to merge 2 commits intouutils:mainfrom
mattsu2020:locale_fix

Conversation

@mattsu2020
Copy link
Copy Markdown
Contributor

@mattsu2020 mattsu2020 commented Apr 16, 2026

Summary

Fix resolve_locales_dir_from_exe_dir() in release builds to use .is_dir() instead of .exists() when checking for locale directories.

In Debian build environments where individual utility binaries (e.g. target/release/wc) exist alongside the multicall coreutils binary, .exists() incorrectly matches the binary file as a "locale directory". This causes setup_localization() to attempt filesystem-based locale loading from the wrong path, resulting in a FluentBundle that lacks utility-specific messages. The translate!() macro then returns raw Fluent keys instead of resolved translations.

Fixes the test failure reported in #11023 (comment):

assertion `left == right` failed: wc should stop after the first stdout write error:
  "wc: wc-error-failed-to-print-result: No space left on device\n"
  left: 0
  right: 1

Changes

  • src/uucore/src/lib/mods/locale.rs: Changed 3 occurrences of .exists() to .is_dir() in resolve_locales_dir_from_exe_dir()

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.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 16, 2026

Merging this PR will degrade performance by 5.61%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 9 improved benchmarks
❌ 6 regressed benchmarks
✅ 294 untouched benchmarks
⏩ 46 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation cksum_blake2b 192.7 ms 183.8 ms +4.86%
Simulation cksum_sha256 1.7 s 1.8 s -4.04%
Simulation cksum_crc32b 13 ms 13.7 ms -5.61%
Simulation cksum_sha2 1.7 s 1.8 s -4.04%
Simulation cksum_sha224 1.7 s 1.8 s -4.04%
Simulation sort_ascii_utf8_locale 15.4 ms 16.1 ms -4.52%
Simulation split_bytes 401.8 µs 389 µs +3.3%
Simulation ls_recursive_deep_tree[(200, 2)] 1.6 ms 1.7 ms -3.47%
Simulation df_deep_directory 385.3 µs 367.6 µs +4.81%
Simulation hostname_basic 159.2 µs 150.8 µs +5.54%
Simulation hostname_ip_lookup[100000] 117.4 µs 86.1 µs +36.31%
Simulation du_max_depth_balanced_tree[(6, 4, 10)] 26.1 ms 25.3 ms +3.12%
Simulation fold_many_lines[100000] 63.8 ms 57.3 ms +11.41%
Simulation fold_custom_width[50000] 25.3 ms 22.9 ms +10.27%
Simulation cut_fields_newline_delim 193.2 µs 185 µs +4.44%

Comparing mattsu2020:locale_fix (205a8aa) with main (5b54e08)

Open in CodSpeed

Footnotes

  1. 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 16, 2026

GNU testsuite comparison:

Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/cut/bounded-memory is now being skipped but was previously passing.
Skip an intermittent issue tests/pr/bounded-memory (was skipped on 'main', now failing)

@oech3
Copy link
Copy Markdown
Contributor

oech3 commented Apr 16, 2026

Is this CodSpeed change real?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants