[lxc-devel] [distrobuilder/master] main: Support multiple instances

monstermunchkin on Github lxc-bot at linuxcontainers.org
Thu Mar 15 10:13:13 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 379 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180315/c74edf78/attachment.bin>
-------------- next part --------------
From 7a5aadf7c3495487710e1377505300440c088fdd Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Thu, 15 Mar 2018 11:11:23 +0100
Subject: [PATCH] main: Support multiple instances

Resolves #65

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 distrobuilder/main.go | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/distrobuilder/main.go b/distrobuilder/main.go
index fa2c998..7a8015e 100644
--- a/distrobuilder/main.go
+++ b/distrobuilder/main.go
@@ -57,6 +57,7 @@ import (
 	"errors"
 	"fmt"
 	"io"
+	"io/ioutil"
 	"os"
 	"path/filepath"
 	"strings"
@@ -99,7 +100,7 @@ func main() {
 	app.PersistentFlags().BoolVar(&globalCmd.flagCleanup, "cleanup", true,
 		"Clean up cache directory")
 	app.PersistentFlags().StringVar(&globalCmd.flagCacheDir, "cache-dir",
-		"/var/cache/distrobuilder", "Cache directory"+"``")
+		"", "Cache directory"+"``")
 	app.PersistentFlags().StringSliceVarP(&globalCmd.flagOptions, "options", "o",
 		[]string{}, "Override options (list of key=value)"+"``")
 
@@ -117,6 +118,17 @@ func main() {
 	buildDirCmd := cmdBuildDir{global: &globalCmd}
 	app.AddCommand(buildDirCmd.command())
 
+	// Create temp directory if the cache directory isn't explicitly set
+	if globalCmd.flagCacheDir == "" {
+		dir, err := ioutil.TempDir("/var/cache", "distrobuilder.")
+		if err != nil {
+			fmt.Fprintf(os.Stderr, "Failed to create cache directory: %s", err)
+			os.Exit(1)
+		}
+
+		globalCmd.flagCacheDir = dir
+	}
+
 	// Run the main command and handle errors
 	err := app.Execute()
 	if err != nil {


More information about the lxc-devel mailing list