Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf13896b

Browse files
committed
Clean up temp file if copy fails
1 parentc63c4a9 commitf13896b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

‎agent/files.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (a *agent) HandleEditFile(rw http.ResponseWriter, r *http.Request) {
190190
return
191191
}
192192

193-
status,err:=a.editFile(path,edits.Edits)
193+
status,err:=a.editFile(r.Context(),path,edits.Edits)
194194
iferr!=nil {
195195
httpapi.Write(ctx,rw,status, codersdk.Response{
196196
Message:err.Error(),
@@ -203,7 +203,7 @@ func (a *agent) HandleEditFile(rw http.ResponseWriter, r *http.Request) {
203203
})
204204
}
205205

206-
func (a*agent)editFile(pathstring,edits []workspacesdk.FileEdit) (int,error) {
206+
func (a*agent)editFile(ctx context.Context,pathstring,edits []workspacesdk.FileEdit) (int,error) {
207207
if!filepath.IsAbs(path) {
208208
returnhttp.StatusBadRequest,xerrors.Errorf("file path must be absolute: %q",path)
209209
}
@@ -247,6 +247,9 @@ func (a *agent) editFile(path string, edits []workspacesdk.FileEdit) (int, error
247247

248248
_,err=io.Copy(tmpfile,replace.Chain(f,transforms...))
249249
iferr!=nil {
250+
ifrerr:=a.filesystem.Remove(tmpfile.Name());rerr!=nil {
251+
a.logger.Warn(ctx,"unable to clean up temp file",slog.Error(rerr))
252+
}
250253
returnhttp.StatusInternalServerError,xerrors.Errorf("edit %s: %w",path,err)
251254
}
252255

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp