Skip to content

Commit 7afd19f

Browse files
authored
on windows, must close the new temp file before removing it (#1115)
Closes #1114
1 parent cafd60f commit 7afd19f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

pkg/util/utilfn/utilfn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,9 +863,9 @@ func AtomicRenameCopy(dstPath string, srcPath string, perms os.FileMode) error {
863863
if err != nil {
864864
return err
865865
}
866-
defer dstFd.Close()
867866
_, err = io.Copy(dstFd, srcFd)
868867
if err != nil {
868+
dstFd.Close()
869869
return err
870870
}
871871
err = dstFd.Close()

pkg/wshrpc/wshremote/wshremote.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,11 @@ func checkIsReadOnly(path string, fileInfo fs.FileInfo, exists bool) bool {
231231
return false
232232
}
233233
tmpFileName := filepath.Join(dirName, "wsh-tmp-"+randHexStr)
234-
_, err = os.Create(tmpFileName)
234+
fd, err := os.Create(tmpFileName)
235235
if err != nil {
236236
return true
237237
}
238+
fd.Close()
238239
os.Remove(tmpFileName)
239240
return false
240241
}

0 commit comments

Comments
 (0)