on windows, must close the new temp file before removing it (#1115)

Closes #1114
This commit is contained in:
Mike Sawka 2024-10-24 09:46:52 -07:00 committed by GitHub
parent cafd60fb1e
commit 7afd19f000
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 2 deletions

View File

@ -863,9 +863,9 @@ func AtomicRenameCopy(dstPath string, srcPath string, perms os.FileMode) error {
if err != nil {
return err
}
defer dstFd.Close()
_, err = io.Copy(dstFd, srcFd)
if err != nil {
dstFd.Close()
return err
}
err = dstFd.Close()

View File

@ -231,10 +231,11 @@ func checkIsReadOnly(path string, fileInfo fs.FileInfo, exists bool) bool {
return false
}
tmpFileName := filepath.Join(dirName, "wsh-tmp-"+randHexStr)
_, err = os.Create(tmpFileName)
fd, err := os.Create(tmpFileName)
if err != nil {
return true
}
fd.Close()
os.Remove(tmpFileName)
return false
}