mirror of https://github.com/perkeep/perkeep.git
devcam: set CAMLI_CACHE_DIR
This change makes osutil.CacheDir return a different value with devcam, allowing us to have a different location for cached blobs from the one used in "prod" mode. Change-Id: I58a88627515ff41cd2be72928d020f4c14736235
This commit is contained in:
parent
90d1df956f
commit
46efff80cc
|
@ -17,13 +17,16 @@ limitations under the License.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"camlistore.org/pkg/blob"
|
"camlistore.org/pkg/blob"
|
||||||
"camlistore.org/pkg/jsonsign"
|
"camlistore.org/pkg/jsonsign"
|
||||||
|
"camlistore.org/pkg/osutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -94,6 +97,14 @@ func setCamdevVars() {
|
||||||
setCamdevVarsFor(nil, false)
|
setCamdevVarsFor(nil, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func rootInTmpDir() (string, error) {
|
||||||
|
user := osutil.Username()
|
||||||
|
if user == "" {
|
||||||
|
return "", errors.New("Could not get username from environment")
|
||||||
|
}
|
||||||
|
return filepath.Join(os.TempDir(), "camliroot-"+user), nil
|
||||||
|
}
|
||||||
|
|
||||||
func setCamdevVarsFor(e *Env, altkey bool) {
|
func setCamdevVarsFor(e *Env, altkey bool) {
|
||||||
var setenv func(string, string) error
|
var setenv func(string, string) error
|
||||||
if e != nil {
|
if e != nil {
|
||||||
|
@ -102,8 +113,14 @@ func setCamdevVarsFor(e *Env, altkey bool) {
|
||||||
setenv = os.Setenv
|
setenv = os.Setenv
|
||||||
}
|
}
|
||||||
|
|
||||||
setenv("CAMLI_CONFIG_DIR", filepath.Join("config", "dev-client-dir"))
|
|
||||||
setenv("CAMLI_AUTH", "userpass:camlistore:pass3179")
|
setenv("CAMLI_AUTH", "userpass:camlistore:pass3179")
|
||||||
|
// env values for clients. server will overwrite them anyway in its setEnvVars.
|
||||||
|
root, err := rootInTmpDir()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
setenv("CAMLI_CACHE_DIR", filepath.Join(root, "client", "cache"))
|
||||||
|
setenv("CAMLI_CONFIG_DIR", filepath.Join("config", "dev-client-dir"))
|
||||||
|
|
||||||
secring := defaultSecring
|
secring := defaultSecring
|
||||||
identity := defaultIdentity
|
identity := defaultIdentity
|
||||||
|
|
|
@ -167,11 +167,11 @@ func (c *serverCmd) checkFlags(args []string) error {
|
||||||
|
|
||||||
func (c *serverCmd) setRoot() error {
|
func (c *serverCmd) setRoot() error {
|
||||||
if c.root == "" {
|
if c.root == "" {
|
||||||
user := osutil.Username()
|
if root, err := rootInTmpDir(); err != nil {
|
||||||
if user == "" {
|
return err
|
||||||
return errors.New("Could not get username from environment")
|
} else {
|
||||||
|
c.root = filepath.Join(root, "port"+c.port)
|
||||||
}
|
}
|
||||||
c.root = filepath.Join(os.TempDir(), "camliroot-"+user, "port"+c.port)
|
|
||||||
}
|
}
|
||||||
log.Printf("Temp dir root is %v", c.root)
|
log.Printf("Temp dir root is %v", c.root)
|
||||||
if c.wipe {
|
if c.wipe {
|
||||||
|
@ -303,6 +303,7 @@ func (c *serverCmd) setEnvVars() error {
|
||||||
setenv("CAMLI_TWITTER_API_KEY", c.twitterAPIKey)
|
setenv("CAMLI_TWITTER_API_KEY", c.twitterAPIKey)
|
||||||
}
|
}
|
||||||
setenv("CAMLI_CONFIG_DIR", "config")
|
setenv("CAMLI_CONFIG_DIR", "config")
|
||||||
|
setenv("CAMLI_CACHE_DIR", filepath.Join(c.root, "cache"))
|
||||||
setenv("CAMLI_APP_BINDIR", "bin")
|
setenv("CAMLI_APP_BINDIR", "bin")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue