Skip to content

libutil: Add openNewFileForWrite helper function, wrap callsites#15141

Merged
Ericson2314 merged 1 commit intomasterfrom
open-new-file-for-write-helper
Feb 4, 2026
Merged

libutil: Add openNewFileForWrite helper function, wrap callsites#15141
Ericson2314 merged 1 commit intomasterfrom
open-new-file-for-write-helper

Conversation

@xokdvium
Copy link
Contributor

@xokdvium xokdvium commented Feb 3, 2026

Motivation

This is purely a fix to use CreateFileW in mingw builds. Also adds some FIXMEs for suspicious symlink following on truncation that can probably be tightened down without any problems (other than nix-channel), but for now this is a no-op change other than consistently using O_CLOEXEC, which is harmless.

Context


Add 👍 to pull requests you find important.

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

This is purely a fix to use CreateFileW in mingw builds. Also adds some
FIXMEs for suspicious symlink following on truncation that can probably
be tightened down without any problems (other than nix-channel), but for
now this is a no-op change other than consistently using O_CLOEXEC, which
is harmless.
@github-actions github-actions bot added the new-cli Relating to the "nix" command label Feb 3, 2026
AutoCloseFD fd = toDescriptor(open(profileFile.string().c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0660));
AutoCloseFD fd = openNewFileForWrite(
profileFile,
0660,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why I did it this way. Generally we override the umask to 0022 everywhere

0666,
{
.truncateExisting = true,
.followSymlinksOnTruncate = true, /* FIXME: Probably shouldn't follow symlinks. */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pretty sure we never expect this to be able to become a symlink, unless the user is doing something very naughty

@Ericson2314 Ericson2314 enabled auto-merge February 3, 2026 23:32
@Ericson2314 Ericson2314 added this pull request to the merge queue Feb 4, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 4, 2026
@Ericson2314 Ericson2314 added this pull request to the merge queue Feb 4, 2026
Merged via the queue into master with commit a357d77 Feb 4, 2026
18 checks passed
@Ericson2314 Ericson2314 deleted the open-new-file-for-write-helper branch February 4, 2026 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-cli Relating to the "nix" command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants