summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'config.go')
-rw-r--r--config.go32
1 files changed, 23 insertions, 9 deletions
diff --git a/config.go b/config.go
index e88a4a2..99ba64d 100644
--- a/config.go
+++ b/config.go
@@ -11,12 +11,12 @@ import (
"go.wit.com/log"
)
-// write to ~/.config/forge/ unless ENV{FORGE_HOME} is set
+// write to ~/.config/forge/ unless ENV{FORGE_CONFIG} is set
func (all *Repos) ConfigSave() error {
- if os.Getenv("FORGE_HOME") == "" {
+ if os.Getenv("FORGE_CONFIG") == "" {
homeDir, _ := os.UserHomeDir()
fullpath := filepath.Join(homeDir, ".config/forge")
- os.Setenv("FORGE_HOME", fullpath)
+ os.Setenv("FORGE_CONFIG", fullpath)
}
if all == nil {
log.Warn("gitpb all == nil")
@@ -35,10 +35,10 @@ func (all *Repos) ConfigSave() error {
// load the ~/.config/forge/ files
func (all *Repos) ConfigLoad() error {
- if os.Getenv("FORGE_HOME") == "" {
+ if os.Getenv("FORGE_CONFIG") == "" {
homeDir, _ := os.UserHomeDir()
fullpath := filepath.Join(homeDir, ".config/forge")
- os.Setenv("FORGE_HOME", fullpath)
+ os.Setenv("FORGE_CONFIG", fullpath)
}
var data []byte
var err error
@@ -52,19 +52,33 @@ func (all *Repos) ConfigLoad() error {
if len(data) == 0 {
// todo: error out if the file is empty?
// try forge.text & forge.json?
+ log.Warn("gitpb.ConfigLoad() repos.pb is empty")
+ return errors.New("gitpb.ConfigLoad() repos.pb is empty")
+ }
+ if all.Repos == nil {
+ log.Warn("gitpb.ConfigLoad() all.Repos == nil")
+ } else {
+ log.Warn("gitpb.ConfigLoad() all.Repos.Len()", all.Len())
}
if err = all.Unmarshal(data); err != nil {
- log.Warn("broken forge.pb config file")
+ log.Warn("gitpb.ConfigLoad() failed", err)
+ if all.Repos == nil {
+ log.Warn("gitpb.ConfigLoad() all.Repos == nil")
+ } else {
+ log.Warn("gitpb.ConfigLoad() all.Repos.Len()", all.Len())
+ log.Warn("gitpb.ConfigLoad() trying to resave the file")
+ all.ConfigSave()
+ }
return err
}
- log.Info("found", len(all.Repos), "repos in ~/.config/forge/repos.pb")
+ log.Info("gitpb.Init()", len(all.Repos), "repos in ~/.config/forge/repos.pb")
return nil
}
return nil
}
func loadFile(filename string) ([]byte, error) {
- fullname := filepath.Join(os.Getenv("FORGE_HOME"), filename)
+ fullname := filepath.Join(os.Getenv("FORGE_CONFIG"), filename)
data, err := os.ReadFile(fullname)
if errors.Is(err, os.ErrNotExist) {
// if file does not exist, just return nil. this
@@ -80,7 +94,7 @@ func loadFile(filename string) ([]byte, error) {
}
func configWrite(filename string, data []byte) error {
- fullname := filepath.Join(os.Getenv("FORGE_HOME"), filename)
+ fullname := filepath.Join(os.Getenv("FORGE_CONFIG"), filename)
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
defer cfgfile.Close()