1
0
mirror of https://github.com/rancher/os.git synced 2025-08-31 22:32:14 +00:00

ros list shows all the active services and any cache available updates

Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
Sven Dowideit
2017-03-03 14:02:44 +10:00
parent 23e51e3b8d
commit 8d941162d8
9 changed files with 378 additions and 122 deletions

30
util/network/cache.go Normal file → Executable file
View File

@@ -5,41 +5,45 @@ import (
"encoding/hex"
"io/ioutil"
"os"
"path/filepath"
"github.com/rancher/os/config"
"github.com/rancher/os/log"
)
const (
cacheDirectory = "/var/lib/rancher/cache/"
)
func locationHash(location string) string {
sum := md5.Sum([]byte(location))
return hex.EncodeToString(sum[:])
}
func cacheLookup(location string) []byte {
cacheFile := cacheDirectory + locationHash(location)
func CacheLookup(location string) ([]byte, error) {
cacheFile := filepath.Join(config.CacheDirectory, location)
bytes, err := ioutil.ReadFile(cacheFile)
if err == nil {
log.Debugf("Using cached file: %s", cacheFile)
return bytes
return bytes, nil
}
return nil
log.Debugf("Cached file not found: %s", cacheFile)
return nil, err
}
func cacheAdd(location string, data []byte) {
tempFile, err := ioutil.TempFile(cacheDirectory, "")
func cacheAdd(location string, data []byte) error {
os.MkdirAll(config.CacheDirectory, 0755)
tempFile, err := ioutil.TempFile(config.CacheDirectory, "")
if err != nil {
return
return err
}
defer os.Remove(tempFile.Name())
_, err = tempFile.Write(data)
if err != nil {
return
return err
}
cacheFile := cacheDirectory + locationHash(location)
cacheFile := filepath.Join(config.CacheDirectory, location)
cacheDir := filepath.Dir(cacheFile)
log.Debugf("writing %s to %s", cacheFile, cacheDir)
os.MkdirAll(cacheDir, 0755)
os.Rename(tempFile.Name(), cacheFile)
return nil
}