From e1c3f11cfab2d11f48f122755c4c3ffdf68ca0e3 Mon Sep 17 00:00:00 2001 From: littleskunk Date: Thu, 20 Dec 2018 14:27:51 +0100 Subject: [PATCH] add overwrite flag (#913) * add storagenode setup --overwrite flag * exit setup with error code --- cmd/captplanet/setup.go | 3 +-- cmd/satellite/main.go | 3 +-- cmd/storagenode/main.go | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cmd/captplanet/setup.go b/cmd/captplanet/setup.go index 8d6de2657..ace10b678 100644 --- a/cmd/captplanet/setup.go +++ b/cmd/captplanet/setup.go @@ -56,8 +56,7 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) { valid, err := fpath.IsValidSetupDir(setupDir) if !setupCfg.Overwrite && !valid { - fmt.Printf("captplanet configuration already exists (%v). rerun with --overwrite\n", setupDir) - return nil + return fmt.Errorf("captplanet configuration already exists (%v). Rerun with --overwrite", setupDir) } else if setupCfg.Overwrite && err == nil { fmt.Println("overwriting existing captplanet config") err = os.RemoveAll(setupDir) diff --git a/cmd/satellite/main.go b/cmd/satellite/main.go index b58bf3e3d..5b103eadc 100644 --- a/cmd/satellite/main.go +++ b/cmd/satellite/main.go @@ -149,8 +149,7 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) { valid, err := fpath.IsValidSetupDir(setupDir) if !setupCfg.Overwrite && !valid { - fmt.Printf("satellite configuration already exists (%v). rerun with --overwrite\n", setupDir) - return nil + return fmt.Errorf("satellite configuration already exists (%v). Rerun with --overwrite", setupDir) } else if setupCfg.Overwrite && err == nil { fmt.Println("overwriting existing satellite config") err = os.RemoveAll(setupDir) diff --git a/cmd/storagenode/main.go b/cmd/storagenode/main.go index ff30bbca8..ba4c5c583 100644 --- a/cmd/storagenode/main.go +++ b/cmd/storagenode/main.go @@ -55,8 +55,9 @@ var ( Storage psserver.Config } setupCfg struct { - CA provider.CASetupConfig - Identity provider.IdentitySetupConfig + CA provider.CASetupConfig + Identity provider.IdentitySetupConfig + Overwrite bool `default:"false" help:"whether to overwrite pre-existing configuration files"` } diagCfg struct { } @@ -112,6 +113,17 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) { return err } + valid, err := fpath.IsValidSetupDir(setupDir) + if !setupCfg.Overwrite && !valid { + return fmt.Errorf("storagenode configuration already exists (%v). Rerun with --overwrite", setupDir) + } else if setupCfg.Overwrite && err == nil { + fmt.Println("overwriting existing satellite config") + err = os.RemoveAll(setupDir) + if err != nil { + return err + } + } + err = os.MkdirAll(setupDir, 0700) if err != nil { return err