Skip to content

Commit e049e26

Browse files
committed
Close cache file before renaming it
On Windows, calling os.Rename(oldpath, newpath) while `oldpath` is open will not create `newpath`. So close `oldpath` before renaming it to avoid the creation of a temporary cache file every time a command is run.
1 parent 3e87a1c commit e049e26

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pkg/api/cache.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,14 @@ func (c *ScalewayCache) Save() error {
239239
if err != nil {
240240
return err
241241
}
242-
defer file.Close()
242+
243243
if err := json.NewEncoder(file).Encode(c); err != nil {
244+
file.Close()
244245
os.Remove(file.Name())
245246
return err
246247
}
247248

249+
file.Close()
248250
if err := os.Rename(file.Name(), c.Path); err != nil {
249251
os.Remove(file.Name())
250252
return err

0 commit comments

Comments
 (0)