Commit 1ea7776
authored
Fix permission denied error in kat update on macOS (#32)
## Summary
- `os.Rename` from a macOS temp dir (`/var/folders/...`) to
`/usr/local/bin` fails with \"permission denied\" because it crosses
filesystem boundaries and requires elevated privileges
- Replace the cross-filesystem rename with `copyFile` (an
`io.Copy`-based helper) that writes the new binary as `kat.new` inside
the destination directory, followed by an atomic same-directory rename
- Add a preflight `os.CreateTemp` check at the start of
`DownloadAndReplace` so permission errors surface immediately — before
any download — with a clear message: _try running with sudo_
- Clean up the `.new` file if the final rename fails so no leftover file
is left behind
## Test plan
- [ ] Run `kat update` as a non-root user with `kat` installed in
`/usr/local/bin` — should now see a clear `permission denied: ... try
running with sudo` message instead of the cryptic rename error
- [x] Run `sudo kat update` — should complete successfully
- [ ] Run `kat update` as a user who owns the install directory — should
complete successfully without sudo1 parent 47a51da commit 1ea7776
2 files changed
+49
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
103 | 105 | | |
104 | 106 | | |
105 | 107 | | |
106 | | - | |
| 108 | + | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
106 | 120 | | |
107 | 121 | | |
108 | 122 | | |
| |||
157 | 171 | | |
158 | 172 | | |
159 | 173 | | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
165 | 178 | | |
166 | | - | |
167 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
168 | 184 | | |
169 | 185 | | |
170 | | - | |
| 186 | + | |
171 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
172 | 192 | | |
173 | 193 | | |
174 | 194 | | |
175 | 195 | | |
176 | 196 | | |
177 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
0 commit comments