From e3900382c7d39a309c40ac37284b09f7b5ede192 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Mon, 12 Sep 2016 14:55:10 -0400 Subject: [PATCH] main: env variable for base directory Signed-off-by: Vincent Batts --- main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 995c94b..2a7cbae 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,9 @@ import ( ) var ( - flVarBase = flag.String("b", filepath.Join(os.Getenv("HOME"), ".local/dedupe-linker/var"), "base directory where files are duplicated") + varBaseDir = filepath.Join(os.Getenv("HOME"), ".local/dedupe-linker/var") + + flVarBase = flag.String("b", varBaseDir, "base directory where files are duplicated") flCipher = flag.String("c", "sha1", "block cipher to use (sha1, or sha256)") flWorkers = flag.Int("w", 2, "workers to do summing") flNoop = flag.Bool("noop", false, "don't do any moving or linking") @@ -26,6 +28,10 @@ func init() { if runtime.NumCPU() > 1 && len(os.Getenv("GOMAXPROCS")) == 0 { runtime.GOMAXPROCS(2) } + + if os.Getenv("VARBASEDIR") != "" { + varBaseDir = filepath.Clean(os.Getenv("VARBASEDIR")) + } } func main() { @@ -35,6 +41,10 @@ func main() { os.Setenv("DEBUG", "1") } + if os.Getenv("DEBUG") != "" { + fmt.Fprintf(os.Stderr, "VARBASEDIR=%q\n", *flVarBase) + } + // TODO the *flCipher has not been checked yet, and would cause the directory to get created ourbase, err := base.NewBase(*flVarBase, *flCipher) if err != nil {