From 6395e339b970c97d21be9a7a70ee55abd21076ec Mon Sep 17 00:00:00 2001 From: Justin Cormack Date: Mon, 20 Nov 2017 13:52:53 +0000 Subject: [PATCH] Do not error if cache/config directory not specified Just use the default. Easier to use as an external library. Signed-off-by: Justin Cormack --- src/moby/build.go | 2 +- src/moby/util.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/moby/build.go b/src/moby/build.go index 56892ae18..415c08c5e 100644 --- a/src/moby/build.go +++ b/src/moby/build.go @@ -142,7 +142,7 @@ func outputImage(image *Image, section string, prefix string, m Moby, idMap map[ // Build performs the actual build process func Build(m Moby, w io.Writer, pull bool, tp string) error { if MobyDir == "" { - return fmt.Errorf("MobyDir for temporary storage not set") + MobyDir = defaultMobyConfigDir() } iw := tar.NewWriter(w) diff --git a/src/moby/util.go b/src/moby/util.go index b262e0066..56afefb88 100644 --- a/src/moby/util.go +++ b/src/moby/util.go @@ -1,6 +1,16 @@ package moby +import ( + "path/filepath" +) + var ( - // MobyDir is the location of the cache directory which should be set by the caller + // MobyDir is the location of the cache directory, defaults to ~/.moby MobyDir string ) + +func defaultMobyConfigDir() string { + mobyDefaultDir := ".moby" + home := homeDir() + return filepath.Join(home, mobyDefaultDir) +}