Skip to content

ngclient: Update root.json link atomically - #3010

Open
Sachith77 wants to merge 1 commit into
theupdateframework:developfrom
Sachith77:fix/atomic-root-symlink
Open

ngclient: Update root.json link atomically#3010
Sachith77 wants to merge 1 commit into
theupdateframework:developfrom
Sachith77:fix/atomic-root-symlink

Conversation

@Sachith77

Copy link
Copy Markdown
Contributor

_update_root_symlink() deletes root.json before creating the new link, so if the process dies in that window or the link can't be created, root.json just stays gone:

after failed update, root.json exists: False
bootstrap=None now fails: FileNotFoundError

Since that's the trust anchor for Updater(bootstrap=None), the client can't start after that. It also runs from a finally block in _load_root(), so this can happen on failure paths too.

Fixed this by creating the link under a temp name and using os.replace() to put it in place, same idea as _persist_file(). I used a fixed .tmp name instead of tempfile since os.symlink() needs a path that doesn't exist yet, and multiple Updater instances aren't supported anyway.

Added a test that fails on develop.

Removing root.json before creating the new link means a failure
leaves no root.json at all, and bootstrap=None can no longer be
used. Use a temp name + os.replace(), like _persist_file() does.

Signed-off-by: Sachith Reddy <sachith.24bcs10403@sst.scaler.com>
@Sachith77
Sachith77 requested a review from a team as a code owner September 3, 2026 11:17
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.

1 participant