@@ -190,7 +190,7 @@ func (a *agent) HandleEditFile(rw http.ResponseWriter, r *http.Request) {
190
190
return
191
191
}
192
192
193
- status , err := a .editFile (path , edits .Edits )
193
+ status , err := a .editFile (r . Context (), path , edits .Edits )
194
194
if err != nil {
195
195
httpapi .Write (ctx , rw , status , codersdk.Response {
196
196
Message : err .Error (),
@@ -203,7 +203,7 @@ func (a *agent) HandleEditFile(rw http.ResponseWriter, r *http.Request) {
203
203
})
204
204
}
205
205
206
- func (a * agent ) editFile (path string , edits []workspacesdk.FileEdit ) (int , error ) {
206
+ func (a * agent ) editFile (ctx context. Context , path string , edits []workspacesdk.FileEdit ) (int , error ) {
207
207
if ! filepath .IsAbs (path ) {
208
208
return http .StatusBadRequest , xerrors .Errorf ("file path must be absolute: %q" , path )
209
209
}
@@ -247,6 +247,9 @@ func (a *agent) editFile(path string, edits []workspacesdk.FileEdit) (int, error
247
247
248
248
_ , err = io .Copy (tmpfile , replace .Chain (f , transforms ... ))
249
249
if err != nil {
250
+ if rerr := a .filesystem .Remove (tmpfile .Name ()); rerr != nil {
251
+ a .logger .Warn (ctx , "unable to clean up temp file" , slog .Error (rerr ))
252
+ }
250
253
return http .StatusInternalServerError , xerrors .Errorf ("edit %s: %w" , path , err )
251
254
}
252
255
0 commit comments