From 80a6219c4b5e212d5723b74658e4d97589630614 Mon Sep 17 00:00:00 2001 From: Ivan Fraixedes Date: Tue, 21 Jan 2020 14:03:58 +0100 Subject: [PATCH] cmd/uplink: Create dir before saving config file Setup command of uplink has to create the configuration directory just before saving the configuration file for making it more robust than creating in the initial state of the process. When creating the directory at the beginning of the process leaves the possibility to delete such directory during the setup process and leads to a failure. Ticket https://storjlabs.atlassian.net/browse/V3-3545 Change-Id: I30db0175e23a597e9675d267b4d7e25d5d4c5119 --- cmd/uplink/cmd/setup.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/uplink/cmd/setup.go b/cmd/uplink/cmd/setup.go index 4d3a2e6dc..ca9c9bcd4 100644 --- a/cmd/uplink/cmd/setup.go +++ b/cmd/uplink/cmd/setup.go @@ -44,11 +44,6 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) { return err } - err = os.MkdirAll(setupDir, 0700) - if err != nil { - return err - } - if setupCfg.NonInteractive { return cmdSetupNonInteractive(cmd, setupDir) } @@ -78,6 +73,12 @@ func cmdSetupNonInteractive(cmd *cobra.Command, setupDir string) error { if err != nil { return err } + + err = os.MkdirAll(setupDir, 0700) + if err != nil { + return err + } + return Error.Wrap(process.SaveConfig(cmd, filepath.Join(setupDir, process.DefaultCfgFilename), process.SaveConfigWithOverride("access", accessData), process.SaveConfigRemovingDeprecated())) @@ -179,6 +180,11 @@ func cmdSetupInteractive(cmd *cobra.Command, setupDir string) error { saveCfgOpts = append(saveCfgOpts, process.SaveConfigWithOverride("access", accessName)) } + err = os.MkdirAll(setupDir, 0700) + if err != nil { + return err + } + configPath := filepath.Join(setupDir, process.DefaultCfgFilename) err = process.SaveConfig(cmd, configPath, saveCfgOpts...) if err != nil {