diff --git a/pkg/cwhub/dataset.go b/pkg/cwhub/dataset.go index 97fd9c5a0..921361e3f 100644 --- a/pkg/cwhub/dataset.go +++ b/pkg/cwhub/dataset.go @@ -4,9 +4,11 @@ import ( "errors" "fmt" "io" + "io/fs" "net/http" "os" "path/filepath" + "runtime" "time" "github.com/sirupsen/logrus" @@ -65,6 +67,18 @@ func downloadFile(url string, destPath string) error { // TODO: use a better way to communicate this fmt.Printf("updated %s\n", filepath.Base(destPath)) + if runtime.GOOS == "windows" { + // On Windows, rename will fail if the destination file already exists + // so we remove it first. + err = os.Remove(destPath) + switch { + case errors.Is(err, fs.ErrNotExist): + break + case err != nil: + return err + } + } + if err = os.Rename(tmpFileName, destPath); err != nil { return err }