Repository navigation
Commit 58cd63e
Add libs/atomicfile and use it for in-place file saves (#6708)
Adds `libs/atomicfile.Write` (same-directory temp file + chmod +
`os.Rename`) and routes in-place file saves through it, so a crash or a
concurrent reader never sees a partial file. The written file always
gets the caller-specified mode and does **not** inherit the replaced
file's permissions. An optional `atomicfile.MkDir(perm)` creates the
parent directory in the same call (the directory mode stays a deliberate
per-caller choice: 0o700 for secrets, 0o755 otherwise).
### Pure refactor (already atomic, behavior unchanged)
- `bundle/direct/dstate/state.go` — direct-engine deployment
`resources.json`
- `libs/auth/storage/filestore.go` — token cache (`atomicWriteFile`
wrapper inlined)
- `libs/aitools/installer/state.go`
- `libs/localenv/constraints.go` (inlined the now-thin
`writeCacheAtomic`)
- `libs/clicompat/clicompat.go`
- `experimental/ssh/internal/sshconfig/knownhosts.go`
- `cmd/genie/conversations.go` — best-effort store (also drops a
double-close)
### Bug fixes
- `libs/cache/file_cache.go` — removed the `os.Remove`-before-`Rename`
hack that deleted the destination first and defeated atomicity.
`os.Rename` already replaces an existing file on Windows.
- `cmd/sandbox/state.go`, `cmd/sandbox/sshconfig.go` — used a fixed
`<path>.tmp` temp name, so concurrent CLI runs collided on it.
`CreateTemp` avoids that.
### New atomicity (was a plain in-place write)
Deployment / sync state (the terraform engine matches the direct engine
now):
- `bundle/statemgmt/state_pull.go` — direct-engine state pulled from the
remote (closes a `// TODO: write + rename`)
- `bundle/deploy/state_update.go` — terraform-engine deployment state
written after deploy
- `bundle/deploy/state_pull.go` — terraform-engine state pulled from the
remote
- `libs/sync/snapshot.go` — the sync snapshot, rewritten every sync and
read back to compute the file diff
Files a user owns (a torn write would lose their content):
- `bundle/configsync/output.go` — local source config files rewritten on
sync
- `libs/completion/{install,uninstall}.go` — the user's shell RC file;
mode preserved via the existing `info.Mode()`. `install` now rewrites
the file instead of `O_APPEND`, matching `uninstall` (`installFish`
wrapper inlined).
- `libs/localenv/pipeline.go` — `pyproject.toml` on merge
- `experimental/ssh/internal/sshconfig/sshconfig.go` — the user's
`~/.ssh/config` (Include add + migration) and the per-host tunnel config
- `experimental/ssh/internal/vscode/settings.go` — the user's VSCode
`settings.json`
CLI-owned state/cache read back on the next run:
- `cmd/labs/project/{login,project}.go` — labs auth and version files
- `cmd/labs/localcache/jsonfile.go` — labs JSON cache
- `bundle/configsync/diff.go` — local config snapshot used for the next
diff
### Deliberately left out
- `libs/databrickscfg/ops.go` — writes via go-ini `SaveTo` in place;
needs a render-to-temp approach, its own PR
- `libs/aitools/installer` file writes — staged in a temp dir already
promoted by rename, so the atomicity boundary is the directory
- WAL files, `O_EXCL` create-once files (locks, greenfield configs), and
append-mode log files — intentionally not atomic-replace
This pull request and its description were written by Isaac.
---------
Co-authored-by: Isaac <[email protected]>1 parent 6c2479b commit 58cd63e
27 files changed
Lines changed: 295 additions & 374 deletions
File tree
- .nextchanges/cli
- bundle
- configsync
- deploy
- direct/dstate
- statemgmt
- cmd
- genie
- labs
- localcache
- project
- sandbox
- experimental/ssh/internal
- sshconfig
- vscode
- libs
- aitools/installer
- atomicfile
- auth/storage
- cache
- clicompat
- completion
- localenv
- sync
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
| 263 | + | |
270 | 264 | | |
271 | 265 | | |
272 | 266 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | 9 | | |
12 | 10 | | |
| 11 | + | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
91 | 90 | | |
92 | 91 | | |
93 | 92 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 93 | + | |
100 | 94 | | |
101 | 95 | | |
102 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | 48 | | |
54 | 49 | | |
55 | 50 | | |
56 | 51 | | |
57 | 52 | | |
58 | 53 | | |
59 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
60 | 57 | | |
61 | 58 | | |
62 | 59 | | |
63 | 60 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | 61 | | |
75 | 62 | | |
76 | | - | |
77 | | - | |
| 63 | + | |
78 | 64 | | |
79 | 65 | | |
80 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
8 | | - | |
9 | 7 | | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
13 | 11 | | |
14 | 12 | | |
| 13 | + | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
56 | 55 | | |
57 | 56 | | |
58 | 57 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | 58 | | |
68 | 59 | | |
69 | 60 | | |
70 | 61 | | |
71 | 62 | | |
72 | | - | |
73 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
74 | 66 | | |
75 | 67 | | |
76 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
969 | 970 | | |
970 | 971 | | |
971 | 972 | | |
972 | | - | |
973 | | - | |
974 | | - | |
975 | | - | |
976 | | - | |
977 | | - | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
988 | | - | |
989 | | - | |
990 | | - | |
991 | | - | |
992 | | - | |
993 | | - | |
994 | | - | |
995 | | - | |
996 | | - | |
| 973 | + | |
997 | 974 | | |
998 | 975 | | |
999 | 976 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
| 198 | + | |
207 | 199 | | |
208 | 200 | | |
209 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 86 | + | |
104 | 87 | | |
105 | 88 | | |
106 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 77 | + | |
89 | 78 | | |
90 | 79 | | |
91 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
124 | 124 | | |
0 commit comments