You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Write files safely everywhere: one robust temp-file + rename (+ optional fsync) helper in libntech #30
With a fixed temp name, anything already at <file>.cfedited gets overwritten. That includes a symlink planted there, since fopen follows it. Without fsync, a power loss can leave an empty or truncated file behind.
To do:
Search more deeply for this pattern before designing anything. The table comes from a quick grep for rename( and fsync(. Also look for fopen(..., "w") / O_TRUNC writes of state and config files, FileWriteOver(), CopyRegularFileDisk*(), WriteJson*-style state writers, and the other daemons (cf-serverd, cf-execd, cf-hub if present).
Add one robust helper to libntech, e.g. FileWriteAtomic(path, data, len, mode, flags):
a. a unique temp name in the same directory, created with O_EXCL;
b. a full write;
c. an optional fsync of the file, plus of the directory after the rename;
d. rename() into place;
e. the temp file removed on every failure path;
f. a clear policy on whether to keep the original owner and mode.
Call it from every writer found, one small upstream-sized PR per call site or per theme.
Upstream constraints apply (~/src/cfengine-all/AGENTS.md): small PRs, and prose proportional to code.
Activity