libutil: Get rid of double-quoting and .string() calls in file-system.cc#15330
Merged
Conversation
Significantly reduces the amount of churny .string() conversions when we don't need them and gets rid of annoying double-quoting issues once again.
xokdvium
commented
Feb 24, 2026
| mode, | ||
| { | ||
| .truncateExisting = true, | ||
| .followSymlinksOnTruncate = true, /* FIXME: Do we want this? */ |
Contributor
Author
There was a problem hiding this comment.
I think we ought to tighten this down for hardening reasons tbh.
Member
There was a problem hiding this comment.
Caller should always open the file descriptor, and this function should go away.
xokdvium
commented
Feb 24, 2026
| auto st = lstat(path); | ||
| if (S_ISREG(st.st_mode)) { | ||
| AutoCloseFD fd = toDescriptor(open(path.string().c_str(), O_RDONLY, 0)); | ||
| AutoCloseFD fd = openFileReadonly(path); /* TODO: O_NOFOLLOW? */ |
Contributor
Author
There was a problem hiding this comment.
This lacked O_NOFOLLOW so technically there was a TOCTOU issue, but since it's just for fsync it's not too bad.
Member
There was a problem hiding this comment.
Yeah this whole file is TOCTOU city :)
Ericson2314
approved these changes
Feb 24, 2026
amaanq
added a commit
to obsidiansystems/nix
that referenced
this pull request
Feb 25, 2026
Six translation units failed to compile or link when targeting `x86_64-w64-mingw32`. `ExecutablePath::render` used `PathView` (narrow `string_view`) where `OsStringView` is needed since `p.native()` returns `std::wstring` on Windows. `createTempFile` used `_wmkstemp`, which mingw does not provide; replaced with `_wmktemp` plus `_wopen`. `PosixSourceAccessor::readLink` needed `.string()` on the `std::filesystem::path` returned by `nix::readLink` after NixOS#15330 changed the return type. `unix-domain-socket.cc` passed a `wchar_t*` to `unlink` and a bare `Descriptor` to `nix::bind`; use `_wunlink` and `toSocket()`. `windows/file-path.cc` had `static` linkage on `maybePath` conflicting with the `extern` declaration in the header.
amaanq
added a commit
to obsidiansystems/nix
that referenced
this pull request
Feb 25, 2026
Several translation units failed to compile for `x86_64-w64-mingw32`, mostly exposed by the file-system refactor in NixOS#15330.
amaanq
added a commit
to obsidiansystems/nix
that referenced
this pull request
Feb 25, 2026
Several translation units failed to compile for `x86_64-w64-mingw32`, mostly exposed by the file-system refactor in NixOS#15330.
amaanq
added a commit
to obsidiansystems/nix
that referenced
this pull request
Feb 25, 2026
Several translation units failed to compile for `x86_64-w64-mingw32`, mostly exposed by the file-system refactor in NixOS#15330.
brittonr
pushed a commit
to brittonr/nix
that referenced
this pull request
Apr 1, 2026
…o-string libutil: Get rid of double-quoting and .string() calls in file-system.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Significantly reduces the amount of churny .string() conversions when
we don't need them and gets rid of annoying double-quoting issues once again.
Note that .fsync() is currently and was always broken on windows due to the required GENERIC_WRITE for FlushFileBuffers.
https://learn.microsoft.com/en-us/previous-versions/ms960615(v=msdn.10)
Context
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.