1
0
mirror of https://github.com/rancher/os.git synced 2025-09-06 17:22:34 +00:00

Fix update cache bug

This commit is contained in:
Jason-ZW
2019-07-01 10:31:34 +08:00
committed by niusmallnan
parent 34afa7824e
commit a37efde319
2 changed files with 26 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/hex"
"io/ioutil"
"os"
"strings"
"github.com/rancher/os/pkg/log"
)
@@ -44,7 +45,15 @@ func cacheAdd(location string, data []byte) {
os.Rename(tempFile.Name(), cacheFile)
}
func cacheRemove(location string) error {
func cacheMove(location string) (string, error) {
cacheFile := cacheDirectory + locationHash(location)
return os.Remove(cacheFile)
tempFile := cacheFile + "_temp"
if err := os.Rename(cacheFile, tempFile); err != nil {
return "", err
}
return tempFile, nil
}
func cacheMoveBack(name string) error {
return os.Rename(name, strings.TrimRight(name, "_temp"))
}