Skip to content

Commit 56ba492

Browse files
committed
On windows, remove file before rewriting it when unzipping.
1 parent 7352060 commit 56ba492

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

pkg/installer/download.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"net/http"
1313
"os"
1414
"path/filepath"
15+
"runtime"
1516
"strings"
1617

1718
"github.com/pkg/errors"
@@ -282,6 +283,18 @@ func extractZipFile(f *zip.File, outputPath string) error {
282283
fMode = 0644
283284
}
284285

286+
// On windows, if the file exists and is read-only, remove it first to avoid "access is denied" errors.
287+
if runtime.GOOS == "windows" {
288+
if _, statErr := os.Stat(outputPath); statErr == nil {
289+
// Try to make file writable in case it's read-only
290+
if chmodErr := os.Chmod(outputPath, 0666); chmodErr != nil {
291+
// Ignore error, try remove anyway
292+
}
293+
// Remove file to allow overwrite
294+
_ = os.Remove(outputPath) // Ignore error: attempt to remove in case it helps
295+
}
296+
}
297+
285298
// Create the output file
286299
outFile, err := os.OpenFile(outputPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, fMode)
287300
if err != nil {

0 commit comments

Comments
 (0)