Skip to content

Conversation

@mattsu2020
Copy link
Contributor

remove unsafe code

@mattsu2020 mattsu2020 marked this pull request as draft January 9, 2026 10:14
- Switch from direct libc::mknod and libc::umask to nix::sys::stat::mknod and nix
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 9, 2026

CodSpeed Performance Report

Merging this PR will degrade performance by 27.39%

Comparing mattsu2020:knod_refactoring (36acc97) with main (a1545ef)

Summary

❌ 8 regressed benchmarks
✅ 274 untouched benchmarks
⏩ 38 skipped benchmarks1

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

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory sort_key_field[500000] 47.8 MB 51.8 MB -7.62%
Memory sort_numeric[500000] 75.5 MB 79.2 MB -4.67%
Memory sort_ascii_only[500000] 22.2 MB 28.3 MB -21.77%
Memory sort_unique_locale[500000] 33.6 MB 39.8 MB -15.5%
Memory sort_mixed_data[500000] 22.9 MB 27.1 MB -15.71%
Memory sort_accented_data[500000] 22.1 MB 28.3 MB -21.79%
Memory sort_long_line[160000] 712.6 KB 981.4 KB -27.39%
Memory cp_large_file[16] 115.3 KB 119.7 KB -3.68%

Footnotes

  1. 38 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.

Changed the visibility of the FileType enum from public to private to encapsulate internal types and improve module encapsulation.
Remove the 'pub' visibility modifier from the Config struct to encapsulate it within the module, preventing external access and improving code organization. This change aligns with best practices for internal data structures that should not be part of the public API.
Add #[cfg(any(feature = "selinux", feature = "smack"))] attributes to Config struct fields
and related code in uumain() to make SELinux/SMACK support optional, preventing compilation
errors when these features are disabled. This improves build flexibility without affecting
core mknod functionality.
- Changed `struct Config<'a>` to `struct Config` to eliminate lifetime parameter
- Updated `context` field from `Option<&'a String>` to `Option<String>` for ownership
- Modified function calls to use `config.context.as_ref()` for borrowing
- Added `.cloned()` when retrieving context from arguments to own the value

This resolves lifetime issues and simplifies the code by avoiding references in the struct.
Reformatted the SMACK label setting block in mknod.rs to remove unnecessary line breaks and indentation, improving readability and aligning with the project's coding style guidelines. No functional changes were made.
@mattsu2020 mattsu2020 marked this pull request as ready for review January 9, 2026 11:47
…lation

Changed the visibility of all fields in the Config struct from public to private to improve encapsulation and prevent direct external access, promoting better code organization and maintainability.
@github-actions
Copy link

github-actions bot commented Jan 9, 2026

GNU testsuite comparison:

Congrats! The gnu test tests/stty/bad-speed is now passing!

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
@mattsu2020 mattsu2020 requested a review from sylvestre January 12, 2026 11:39
…tants

Replace MODE_RW_UGO constant from octal 0o666 to bitwise OR of S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH for improved readability and maintainability. Added necessary import from nix::libc.
Wrap the bitwise OR expression in parentheses and cast to u32 to ensure type consistency and resolve potential compilation issues.
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/shuf/shuf-reservoir (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/sort/sort-stale-thread-mem (fails in this run but passes in the 'main' branch)

Reformat the MODE_RW_UGO constant declaration for consistency and to adhere to Rust formatting guidelines.
The bitwise OR operation on the file permission flags already yields a u32 value, making the explicit cast unnecessary and improving code clarity.
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tty/tty-eof (fails in this run but passes in the 'main' branch)

Ensure MODE_RW_UGO is explicitly typed as u32 on specified platforms to resolve compilation errors where the bitwise OR expression doesn't implicitly cast. This maintains consistent behavior across all supported operating systems.
target_os = "freebsd",
target_os = "redox",
)))]
const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this cleaner would it make more sense to just keep everything as mode_t? it would always be the correct type for every platform so you would never have to cast in the code?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than that everything looks great, glad that you cleaned up the tech debt with the SELinux and smack code to make sure its not even compiled when the feature isn't enabled

Copy link
Contributor Author

@mattsu2020 mattsu2020 Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The declaration part looks clean, but because conversion occurs in the implementation part, Clippy issues a warning.

https://github.com/uutils/coreutils/actions/runs/21087578799/job/60653640976?pr=10138

Remove conditional compilation based on target OS for the MODE_RW_UGO constant,
changing it to use the standard libc mode_t type for better portability and type safety.
Update usages in uumain and parse_mode to cast to u32 as required by the functions.
- Moved `mode_t` to the end of the import list for consistency
- Inlined the `MODE_RW_UGO` constant definition to a single line for brevity
- No functional changes, improves code readability and style
…_UGO

Replace `as u32` casts with `u32::from()` to fix clippy::unnecessary_cast lint warnings, improving code clarity and adhering to Rust best practices. This affects default mode handling in mknod utility.
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.

3 participants