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:
mpl 2014-08-21 18:06:32 +02:00
parent 90d1df956f
commit 46efff80cc
2 changed files with 23 additions and 5 deletions

View File

@ -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

View File

@ -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
}