Skip to content

Commit

Permalink
Fix fs.copy/fs.move force on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafflesiaceae committed May 22, 2022
1 parent b8c3723 commit 3234dec
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions fs/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"os"
"path/filepath"
"runtime"

"go.starlark.net/starlark"
)
Expand Down Expand Up @@ -121,6 +122,18 @@ func CopyFile(from string, to string) error {
return err
}

if runtime.GOOS == "windows" {
// os.OpenFile fails on Windows when trying to overwrite existing
// read-only files, to prevent this we delete 'to' before

if _, err := os.Stat(to); !os.IsNotExist(err) {
if err = os.Remove(to); err != nil {
return err
}
}

}

// Create File
toStream, err := os.OpenFile(to, os.O_RDWR|os.O_CREATE|os.O_TRUNC, si.Mode())
if err != nil {
Expand Down

0 comments on commit 3234dec

Please sign in to comment.