fix(uucore): use is_dir() instead of exists() for locale path resolution#11851
Open
mattsu2020 wants to merge 2 commits intouutils:mainfrom
Open
fix(uucore): use is_dir() instead of exists() for locale path resolution#11851mattsu2020 wants to merge 2 commits intouutils:mainfrom
mattsu2020 wants to merge 2 commits intouutils:mainfrom
Conversation
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.
Merging this PR will degrade performance by 5.61%
|
| 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)
Footnotes
-
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. ↩
|
GNU testsuite comparison: |
Contributor
|
Is this CodSpeed change real? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 multicallcoreutilsbinary,.exists()incorrectly matches the binary file as a "locale directory". This causessetup_localization()to attempt filesystem-based locale loading from the wrong path, resulting in a FluentBundle that lacks utility-specific messages. Thetranslate!()macro then returns raw Fluent keys instead of resolved translations.Fixes the test failure reported in #11023 (comment):
Changes
src/uucore/src/lib/mods/locale.rs: Changed 3 occurrences of.exists()to.is_dir()inresolve_locales_dir_from_exe_dir()