Files
Oleksiy Syvokon 79fe6a645f gpui: Add a way to write credentials only if none exist (#66062)
Apps that keep a shared secret in the system keychain, such as an
encryption key, create it on first use. With only `read_credentials` and
`write_credentials`, two processes can both find no secret, and the
second write then replaces the first. Data encrypted with the replaced
secret can no longer be read.

Add `write_credentials_if_not_exists`, which returns `true` if it wrote
the credentials and `false` if they already existed. It never replaces
an existing secret.

On macOS this is a single atomic `SecItemAdd`: an existing item with the
same URL and username makes it return `false`. Other platforms and
providers get a default that reads and then writes. That default never
overwrites credentials it can see, but two concurrent callers can still
race. A failed read, including a cancelled Keychain prompt, never
writes.

`write_credentials` keeps its update behavior.



Release Notes:

- [GPUI] Added `write_credentials_if_not_exists`, which never replaces
existing credentials and is atomic on macOS
2026-10-23 21:59:20 +00:00
..