From d4ace5e4a067027a7f412b80684e24d4d23eb5d4 Mon Sep 17 00:00:00 2001 From: Jonathan Boulle Date: Wed, 21 Jan 2015 11:37:08 -0800 Subject: [PATCH] stage0: add docstring + create parent dir --- stage0/run.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/stage0/run.go b/stage0/run.go index ab504f5..df83b21 100644 --- a/stage0/run.go +++ b/stage0/run.go @@ -81,6 +81,10 @@ func Setup(cfg Config) (string, error) { log.SetOutput(os.Stderr) } + if err := os.MkdirAll(cfg.ContainersDir, 0700); err != nil { + return "", fmt.Errorf("error creating containers directory: %v", err) + } + // Create a unique directory for this container cuuid, dir, err := makeUniqueContainer(cfg.ContainersDir) if err != nil { @@ -220,6 +224,11 @@ func Run(cfg Config, dir string) { } } +// makeUniqueContainer creates a subdirectory (representing a container) +// within the given parent directory. On success, it returns a UUID +// representing the created container and the full path to the new directory. +// The UUID is guaranteed to be unique within the parent directory. +// The parent directory MUST exist and be writeable. func makeUniqueContainer(pdir string) (*types.UUID, string, error) { // Arbitrary limit so we don't spin forever for i := 0; i <= 100; i++ {