-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
mKnod: Refactor to remove unsafe code #10138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Switch from direct libc::mknod and libc::umask to nix::sys::stat::mknod and nix
fbbf917 to
da73288
Compare
CodSpeed Performance ReportMerging this PR will degrade performance by 27.39%Comparing Summary
Performance Changes
Footnotes
|
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.
…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.
|
GNU testsuite comparison: |
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
…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.
…utils into knod_refactoring
Wrap the bitwise OR expression in parentheses and cast to u32 to ensure type consistency and resolve potential compilation issues.
|
GNU testsuite comparison: |
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.
|
GNU testsuite comparison: |
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.
src/uu/mknod/src/mknod.rs
Outdated
| target_os = "freebsd", | ||
| target_os = "redox", | ||
| )))] | ||
| const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
remove unsafe code