forked from fergusstrange/embedded-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache_locator.go
31 lines (28 loc) · 952 Bytes
/
cache_locator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package embeddedpostgres
import (
"fmt"
"os"
"path/filepath"
)
// CacheLocator retrieves the location of the Postgres binary cache returning it to location.
// The result of whether this cache is present will be returned to exists.
type CacheLocator func() (location string, exists bool)
func defaultCacheLocator(versionStrategy VersionStrategy) CacheLocator {
return func() (string, bool) {
cacheDirectory := ".embedded-postgres-go"
if userHome, err := os.UserHomeDir(); err == nil {
cacheDirectory = filepath.Join(userHome, ".embedded-postgres-go")
}
operatingSystem, architecture, version := versionStrategy()
cacheLocation := filepath.Join(cacheDirectory,
fmt.Sprintf("embedded-postgres-binaries-%s-%s-%s.txz",
operatingSystem,
architecture,
version))
info, err := os.Stat(cacheLocation)
if err != nil {
return cacheLocation, os.IsExist(err) && !info.IsDir()
}
return cacheLocation, !info.IsDir()
}
}