Skip to content

libutil: Get rid of double-quoting and .string() calls in file-system.cc#15330

Merged
Ericson2314 merged 1 commit into
masterfrom
file-system-get-rid-of-fs-to-string
Feb 24, 2026
Merged

libutil: Get rid of double-quoting and .string() calls in file-system.cc#15330
Ericson2314 merged 1 commit into
masterfrom
file-system-get-rid-of-fs-to-string

Conversation

@xokdvium
Copy link
Copy Markdown
Contributor

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)

The file handle must have GENERIC_WRITE access to the file.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

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 xokdvium requested a review from edolstra as a code owner February 24, 2026 21:35
mode,
{
.truncateExisting = true,
.followSymlinksOnTruncate = true, /* FIXME: Do we want this? */
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we ought to tighten this down for hardening reasons tbh.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caller should always open the file descriptor, and this function should go away.

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? */
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lacked O_NOFOLLOW so technically there was a TOCTOU issue, but since it's just for fsync it's not too bad.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this whole file is TOCTOU city :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still is...

@Ericson2314 Ericson2314 added this pull request to the merge queue Feb 24, 2026
Merged via the queue into master with commit cf1ead7 Feb 24, 2026
18 checks passed
@Ericson2314 Ericson2314 deleted the file-system-get-rid-of-fs-to-string branch February 24, 2026 23:12
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
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