From 46efff80ccdeff768d028cbc16be8f27d9cfc604 Mon Sep 17 00:00:00 2001 From: mpl Date: Thu, 21 Aug 2014 18:06:32 +0200 Subject: [PATCH] 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 --- dev/devcam/env.go | 19 ++++++++++++++++++- dev/devcam/server.go | 9 +++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/dev/devcam/env.go b/dev/devcam/env.go index bb3616034..4d4518fe4 100644 --- a/dev/devcam/env.go +++ b/dev/devcam/env.go @@ -17,13 +17,16 @@ limitations under the License. package main import ( + "errors" "flag" + "log" "os" "path/filepath" "strings" "camlistore.org/pkg/blob" "camlistore.org/pkg/jsonsign" + "camlistore.org/pkg/osutil" ) const ( @@ -94,6 +97,14 @@ func setCamdevVars() { 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) { var setenv func(string, string) error if e != nil { @@ -102,8 +113,14 @@ func setCamdevVarsFor(e *Env, altkey bool) { setenv = os.Setenv } - setenv("CAMLI_CONFIG_DIR", filepath.Join("config", "dev-client-dir")) 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 identity := defaultIdentity diff --git a/dev/devcam/server.go b/dev/devcam/server.go index e47dc98c3..eb5dd3cdc 100644 --- a/dev/devcam/server.go +++ b/dev/devcam/server.go @@ -167,11 +167,11 @@ func (c *serverCmd) checkFlags(args []string) error { func (c *serverCmd) setRoot() error { if c.root == "" { - user := osutil.Username() - if user == "" { - return errors.New("Could not get username from environment") + if root, err := rootInTmpDir(); err != nil { + return err + } 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) if c.wipe { @@ -303,6 +303,7 @@ func (c *serverCmd) setEnvVars() error { setenv("CAMLI_TWITTER_API_KEY", c.twitterAPIKey) } setenv("CAMLI_CONFIG_DIR", "config") + setenv("CAMLI_CACHE_DIR", filepath.Join(c.root, "cache")) setenv("CAMLI_APP_BINDIR", "bin") return nil }