paramfetch: respect FIL_PROOFS_PARAMETER_CACHE

This commit is contained in:
Łukasz Magiera 2019-12-10 13:09:56 +01:00
parent 9246788bff
commit 707f7878e3

View File

@ -25,6 +25,7 @@ var log = logging.Logger("build")
//const gateway = "http://198.211.99.118/ipfs/" //const gateway = "http://198.211.99.118/ipfs/"
const gateway = "https://ipfs.io/ipfs/" const gateway = "https://ipfs.io/ipfs/"
const paramdir = "/var/tmp/filecoin-proof-parameters" const paramdir = "/var/tmp/filecoin-proof-parameters"
const dirEnv = "FIL_PROOFS_PARAMETER_CACHE"
type paramFile struct { type paramFile struct {
Cid string `json:"cid"` Cid string `json:"cid"`
@ -39,8 +40,15 @@ type fetch struct {
errs []error errs []error
} }
func getParamDir() string {
if os.Getenv(dirEnv) == "" {
return paramdir
}
return os.Getenv(dirEnv)
}
func GetParams(storageSize uint64) error { func GetParams(storageSize uint64) error {
if err := os.Mkdir(paramdir, 0755); err != nil && !os.IsExist(err) { if err := os.Mkdir(getParamDir(), 0755); err != nil && !os.IsExist(err) {
return err return err
} }
@ -70,7 +78,7 @@ func (ft *fetch) maybeFetchAsync(name string, info paramFile) {
go func() { go func() {
defer ft.wg.Done() defer ft.wg.Done()
path := filepath.Join(paramdir, name) path := filepath.Join(getParamDir(), name)
err := ft.checkFile(path, info) err := ft.checkFile(path, info)
if !os.IsNotExist(err) && err != nil { if !os.IsNotExist(err) && err != nil {