Skip to content

Commit 6e242b5

Browse files
committed
Remove existing cached file before overwrite
The permission for the cache file is set to `0500` by default and when we try to overwrite this file without removing the current file it failed with following error because the `CopyFileContents` open the file with `os.O_RDWR` and since the file doesn't have write permission thus the error. ``` Unable to download oc [open /home/prkumar/.crc/bin/oc/oc: permission denied] Cannot create dst file '/home/prkumar/.crc/bin/oc/oc' ```
1 parent 6220095 commit 6e242b5

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

pkg/crc/cache/cache.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ func (c *Cache) CacheBinary() error {
8585

8686
for _, extractedFilePath := range extractedFiles {
8787
finalBinaryPath := filepath.Join(c.destDir, filepath.Base(extractedFilePath))
88+
// If the file exists then remove it (ignore error) first before copy because with `0500` permission
89+
// it is not possible to overwrite the file.
90+
os.Remove(finalBinaryPath)
8891
err = crcos.CopyFileContents(extractedFilePath, finalBinaryPath, 0500)
8992
if err != nil {
9093
return err

0 commit comments

Comments
 (0)