Skip to content

Commit

Permalink
Remove existing cached file before overwrite
Browse files Browse the repository at this point in the history
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'
```
  • Loading branch information
praveenkumar committed Jul 6, 2020
1 parent 6220095 commit 6e242b5
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/crc/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func (c *Cache) CacheBinary() error {

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

0 comments on commit 6e242b5

Please sign in to comment.