From c118636d38460b343a370cc80c4dbddab54e4199 Mon Sep 17 00:00:00 2001 From: Adam Borocz Date: Fri, 15 May 2020 15:20:06 +0100 Subject: [PATCH] Fix for empty directory left behind after failed `package create_env` Closes #2 --- cmd/configstore/package-create.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/configstore/package-create.go b/cmd/configstore/package-create.go index 92edb50..7f41120 100644 --- a/cmd/configstore/package-create.go +++ b/cmd/configstore/package-create.go @@ -36,11 +36,13 @@ func cmdPackageCreate(c *cli.Context) error { isInsecure := c.Bool("insecure") if !isInsecure && masterKey == "" { + cleanup(dir) return errors.New("you have to specify --master-key if --insecure is not set") } _, err := client.InitConfigstore(dir, region, role, masterKey, isInsecure) if err != nil { + cleanup(dir) return err } @@ -53,3 +55,9 @@ func cmdPackageCreate(c *cli.Context) error { return nil } + +func cleanup(dir string) { + if err := os.Remove(dir); err != nil { + fmt.Printf("WARN: Failed to clean up directory \"%s\" after initialisation error - you need to manually remove it\n", dir) + } +}