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
This commit is contained in:
Ivan Fraixedes 2020-01-21 14:03:58 +01:00 committed by Michal Niewrzal
parent 6502454947
commit 80a6219c4b

View File

@ -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 {