Skip to content

Commit 6a932e0

Browse files
committed
Recoded user.Current for cross-compiling
1 parent d660799 commit 6a932e0

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

cache.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ package main
22

33
import (
44
"encoding/json"
5-
"fmt"
65
"io/ioutil"
76
"os"
8-
"os/user"
7+
"path/filepath"
98
"regexp"
109
"strings"
1110
"sync"
@@ -53,29 +52,32 @@ type ScalewayIdentifier struct {
5352

5453
// NewScalewayCache loads a per-user cache
5554
func NewScalewayCache() (*ScalewayCache, error) {
56-
u, err := user.Current()
57-
if err != nil {
58-
return nil, err
55+
homeDir := os.Getenv("HOME") // *nix
56+
if homeDir == "" { // Windows
57+
homeDir = os.Getenv("USERPROFILE")
58+
}
59+
if homeDir == "" {
60+
homeDir = "/tmp"
5961
}
60-
cache_path := fmt.Sprintf("%s/.scw-cache.db", u.HomeDir)
61-
_, err = os.Stat(cache_path)
62+
cachePath := filepath.Join(homeDir, ".scw-cache.db")
63+
_, err := os.Stat(cachePath)
6264
if os.IsNotExist(err) {
6365
return &ScalewayCache{
6466
Images: make(map[string]string),
6567
Snapshots: make(map[string]string),
6668
Bootscripts: make(map[string]string),
6769
Servers: make(map[string]string),
68-
Path: cache_path,
70+
Path: cachePath,
6971
}, nil
7072
} else if err != nil {
7173
return nil, err
7274
}
73-
file, err := ioutil.ReadFile(cache_path)
75+
file, err := ioutil.ReadFile(cachePath)
7476
if err != nil {
7577
return nil, err
7678
}
7779
var cache ScalewayCache
78-
cache.Path = cache_path
80+
cache.Path = cachePath
7981
err = json.Unmarshal(file, &cache)
8082
if err != nil {
8183
return nil, err

0 commit comments

Comments
 (0)