Skip to content

uucore(fs): make display_permissions_unix cross-platform#11538

Merged
sylvestre merged 1 commit intouutils:mainfrom
kaladron:unix-fs
Mar 30, 2026
Merged

uucore(fs): make display_permissions_unix cross-platform#11538
sylvestre merged 1 commit intouutils:mainfrom
kaladron:unix-fs

Conversation

@kaladron
Copy link
Copy Markdown
Contributor

Remove the #[cfg(unix)] gate from display_permissions_unix and its helper get_file_display. Change the parameter from libc::mode_t to u32 (Metadata::mode() already returns u32, so no cast or information loss).

Add pub mod mode to uucore::fs with portable u32 constants for all POSIX S_I* values (S_IFMT, S_IFSOCK, S_IFLNK, S_IFREG, S_IFBLK, S_IFDIR, S_IFCHR, S_IFIFO, S_ISUID, S_ISGID, S_ISVTX, and all nine rwx bits). Callers can import uucore::fs::mode::* instead of libc, without requiring a Unix target.

Replace the has!() macro calls in display_permissions_unix with explicit bitwise & != 0 checks, which work without a type-specific macro.

Update chmod and mv to drop the libc::mode_t import and the as mode_t casts at each call site. Update is_stdin_directory to use mode::S_IFMT and mode::S_IFDIR instead of the libc imports.

Remove #[cfg(unix)] from test_display_permissions and test_get_file_display so both tests compile and run on all platforms.

@kaladron kaladron marked this pull request as ready for review March 29, 2026 12:04
@kaladron
Copy link
Copy Markdown
Contributor Author

kaladron commented Mar 29, 2026

This is something I want for the uutils/tar code. Otherwise I will wind up duplicating this logic in the code and I think it would be better to combine them for making the code cross-platform for Unix and Windows.

@kaladron kaladron marked this pull request as draft March 29, 2026 12:08
@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (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/printf/printf-surprise is now being skipped but was previously passing.
Note: The gnu test tests/unexpand/bounded-memory is now being skipped but was previously passing.
Congrats! The gnu test tests/tail/tail-n0f is now passing!

Remove the #[cfg(unix)] gate from display_permissions_unix and its
helper get_file_display. Change the parameter from libc::mode_t to u32
(Metadata::mode() already returns u32, so no cast or information loss).

Add pub mod mode to uucore::fs with portable u32 constants for all POSIX
S_I* values (S_IFMT, S_IFSOCK, S_IFLNK, S_IFREG, S_IFBLK, S_IFDIR,
S_IFCHR, S_IFIFO, S_ISUID, S_ISGID, S_ISVTX, and all nine rwx bits).
Callers can import uucore::fs::mode::* instead of libc, without
requiring a Unix target.

Replace the has!() macro calls in display_permissions_unix with explicit
bitwise & != 0 checks, which work without a type-specific macro.

Update chmod and mv to drop the libc::mode_t import and the as mode_t
casts at each call site. Update is_stdin_directory to use mode::S_IFMT
and mode::S_IFDIR instead of the libc imports.

Remove #[cfg(unix)] from test_display_permissions and test_get_file_display
so both tests compile and run on all platforms.
@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/rm/isatty (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)

@kaladron kaladron marked this pull request as ready for review March 29, 2026 12:39
@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tty/tty-eof (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/tail/tail-n0f is now passing!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 29, 2026

Merging this PR will improve performance by 5.18%

⚡ 1 improved benchmark
✅ 301 untouched benchmarks
⏩ 46 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation cp_large_file[16] 279.2 µs 265.4 µs +5.18%

Comparing kaladron:unix-fs (42db536) with main (319a06c)

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.

@sylvestre sylvestre merged commit a21177e into uutils:main Mar 30, 2026
162 checks passed
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