Skip to content

Commit 643fe38

Browse files
authored
fix: use temp file on same device with mcp file edit (coder#20477)
Otherwise you can get errors like "invalid cross-device link".
1 parent c827a08 commit 643fe38

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

agent/files.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ func (a *agent) editFile(ctx context.Context, path string, edits []workspacesdk.
250250
transforms[i] = replace.String(edit.Search, edit.Replace)
251251
}
252252

253-
tmpfile, err := afero.TempFile(a.filesystem, "", filepath.Base(path))
253+
// Create an adjacent file to ensure it will be on the same device and can be
254+
// moved atomically.
255+
tmpfile, err := afero.TempFile(a.filesystem, filepath.Dir(path), filepath.Base(path))
254256
if err != nil {
255257
return http.StatusInternalServerError, err
256258
}

0 commit comments

Comments
 (0)