Review report

core: PR #36677

1 minor finding · 3 suggestions

Findings

Link

[minor] · The unconditional <cstring> include fails IWYU on Linux

Linux excludes the only std::strchr calls, so the enforced IWYU job removes the unused include and detects a diff.

Location: src/util/fs.cpp:11 (head).

Details and suggested fix

The <cstring> include is unconditional, but its only users are std::strchr calls in the non-Linux, non-Windows POSIX branch. On Linux, that branch is preprocessed away, leaving the include unused in a file covered by the enforced IWYU job. The job runs fix_includes.py and fails if it changes files, so IWYU should remove the include and fail the job. Simply deleting it would break macOS and BSD builds, which need it. Guard the include with #if !defined(__linux__) && !defined(WIN32) so it is present where its users are compiled. IWYU was not run; this conclusion follows from the Linux-preprocessed translation unit.


Optional improvements

Link

[suggestion] · The test does not cover key fopen mode semantics on macOS and BSD

The new test checks FD_CLOEXEC for a fresh file opened with "wb", but does not verify exclusive creation or append behavior in the non-Linux POSIX fallback.

Location: src/test/fs_tests.cpp:153 (head).

Details and suggested fix

On macOS and BSD, fsbridge::fopen maps mode strings to open flags and then calls fdopen, rather than letting libc interpret the mode. The mapping is correct for modes used by current callers, but the new test only checks FD_CLOEXEC after opening a fresh file with "wb". Existing coverage indirectly exercises "rb+", but does not check two other behaviors callers rely on: "wbx" and "wx" must fail on an existing file without changing it, and "a" and "ab" must preserve existing bytes and append after them. Only the macOS native CI job runs this branch, so a later mapping error could go unnoticed. Add tests that pre-create a file with known contents, verify that "wbx" fails without changing them and that "ab" appends, and check the noninheritable flag on each successful open.


Link

[suggestion] · Fixup commits leave the history non-bisectable and messages describe superseded code

Some intermediate commits do not build on Windows, and the first commit message does not describe the final implementation.

Location: src/util/fs.cpp:26 (head).

Details and suggested fix

The commit sequence includes fixup commits: one fixes Windows compilation of the test added earlier, and another adds the <cstring> include needed by the newly introduced std::strchr calls. These intermediate commits are therefore not bisectable on Windows. The first commit message also describes POSIX use of the e mode, while the final code uses it only on Linux; its subject contains a typo, and two other subjects lack a component prefix. Squash the changes into one util: commit and one test: commit that build on all platforms, with messages describing the final per-platform approach: e on Linux, N on Windows, and open(O_CLOEXEC) followed by fdopen elsewhere.


Link

[suggestion] · New code has formatting inconsistencies and an unused test include

The new switch and test include block do not follow src/.clang-format, and the test does not use <unistd.h>.

Location: src/util/fs.cpp:37 (head).

Details and suggested fix

In fs.cpp, the case labels are indented despite IndentCaseLabels: false; the if lacks the required space before its condition, and the ternary has an extra space. In fs_tests.cpp, the includes inside #ifdef WIN32 are indented despite IndentPPDirectives: None. The test does not use <unistd.h>: fileno comes from <stdio.h>, and fcntl comes from <fcntl.h>. Run git diff -U0 | ./contrib/devtools/clang-format-diff.py -p1 -i and remove <unistd.h>.


Coverage details