Setup improvements (#3504)

* Improve setup redirects
* Add network database warning
* Add cache directory to setup
This commit is contained in:
DingDongSoLong4
2023-03-06 23:28:19 +02:00
committed by GitHub
parent 42fde9bc9f
commit 71e1451c94
9 changed files with 168 additions and 47 deletions

View File

@@ -100,6 +100,8 @@ type SetupInput struct {
DatabaseFile string `json:"databaseFile"`
// Empty to indicate default
GeneratedLocation string `json:"generatedLocation"`
// Empty to indicate default
CacheLocation string `json:"cacheLocation"`
}
type Manager struct {
@@ -588,6 +590,9 @@ func setSetupDefaults(input *SetupInput) {
if input.GeneratedLocation == "" {
input.GeneratedLocation = filepath.Join(configDir, "generated")
}
if input.CacheLocation == "" {
input.CacheLocation = filepath.Join(configDir, "cache")
}
if input.DatabaseFile == "" {
input.DatabaseFile = filepath.Join(configDir, "stash-go.sqlite")
@@ -633,6 +638,17 @@ func (s *Manager) Setup(ctx context.Context, input SetupInput) error {
s.Config.Set(config.Generated, input.GeneratedLocation)
}
// create the cache directory if it does not exist
if !c.HasOverride(config.Cache) {
if exists, _ := fsutil.DirExists(input.CacheLocation); !exists {
if err := os.Mkdir(input.CacheLocation, 0755); err != nil {
return fmt.Errorf("error creating cache directory: %v", err)
}
}
s.Config.Set(config.Cache, input.CacheLocation)
}
// set the configuration
if !c.HasOverride(config.Database) {
s.Config.Set(config.Database, input.DatabaseFile)