corso/src/cli/flags/filesystem.go
ashmrtn ca3ca60ba4
Update repo init for partial init case (#5060)
Unclear if this is precisely the path we want to take to handle possible
partial repo initialization so feel free to leave suggestions if a
different behavior would be better

Update the repo init logic to continue if the repo is marked as already existing. If it already exists then the process will try to update persistent config info in the repo. If the repo already exists but some connection credential is incorrect then stack errors such that both the reason for the connect failure and the fact that the repo already exists are both visible.

Manually tested attempting to initialize a repo that was already
initialized but using a different passphrase and got the output:
```text
Error: initializing repository: a repository was already initialized with that configuration: connecting to kopia repo: unable to create format manager: invalid repository password: repo already exists: repository already initialized
exit status 1
```

Attempting to initialize a repo again using the same passphrase resulted
in a success message with no errors reported

Unfortunately I can't really add unit tests to ensure the config ends up
the way we expect because I have no way to trigger an error partway through
kopia's init logic (or even just after it) without some non-trivial code
refactoring

---

#### Does this PR need a docs update or release note?

- [x]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [ ]  No

#### Type of change

- [ ] 🌻 Feature
- [x] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Test Plan

- [x] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
2024-01-30 18:27:35 +00:00

49 lines
945 B
Go

package flags
import (
"github.com/spf13/cobra"
"github.com/alcionai/corso/src/pkg/storage"
)
// filesystem flag names
const (
FilesystemPathFN = "path"
)
// filesystem flag values
var (
FilesystemPathFV string
)
func AddFilesystemFlags(cmd *cobra.Command) {
fs := cmd.Flags()
AddAzureCredsFlags(cmd)
AddCorsoPassphaseFlags(cmd)
fs.StringVar(
&FilesystemPathFV,
FilesystemPathFN,
"",
"path to local or network storage")
cobra.CheckErr(cmd.MarkFlagRequired(FilesystemPathFN))
}
func FilesystemFlagOverrides(cmd *cobra.Command) map[string]string {
fs := GetPopulatedFlags(cmd)
return PopulateFilesystemFlags(fs)
}
func PopulateFilesystemFlags(flagset PopulatedFlags) map[string]string {
fsOverrides := map[string]string{
storage.StorageProviderTypeKey: storage.ProviderFilesystem.String(),
}
if _, ok := flagset[FilesystemPathFN]; ok {
fsOverrides[FilesystemPathFN] = FilesystemPathFV
}
return fsOverrides
}