* mkdir: create directories atomically with correct permissions
Fix#10022: mkdir -m MODE was creating directories with umask-based
permissions first, then calling chmod afterward. This left a brief
window where the directory existed with wrong permissions.
Now we match GNU mkdir behavior by temporarily setting umask to 0
before the mkdir syscall, passing the exact requested mode to the
kernel, then restoring the original umask. The directory is created
atomically with the correct permissions.
Before (two syscalls, race condition):
mkdir("dir", 0777) -> created with 0755 (umask applied)
chmod("dir", 0700) -> fixed afterward
After (single syscall, atomic):
umask(0)
mkdir("dir", 0700) -> created with exact mode
umask(original)
Also added tests to verify -m MODE bypasses umask correctly.
* mkdir: add UmaskGuard for panic-safe umask restoration
Add RAII guard to ensure umask is restored even on panic. Encapsulate
unsafe umask calls in UmaskGuard::set() for a safe interface.
* mkdir: fix clippy and spelling warnings
- Add RAII to spell-checker ignore list
- Narrow chmod cfg to Linux only (only used for ACL bits)
* mkdir: fix unused import on non-Linux
FromIo is only used in chmod, which is now Linux-only.
* --version should just print the command name, not the path
This will fix the parsing for old autoconf
Closes: #8880
* Update tests/by-util/test_mkdir.rs
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
---------
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
The dir/. special case was handled correctly, but dir/./ was not,
breaking gcc builds, which run:
../../../../src/libstdc++-v3/../install-sh -c -d debug/./
Bug-Ubuntu: https://bugs.launchpad.net/bugs/2117466