summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-21 19:48:53 -0600
committerJeff Carr <[email protected]>2024-11-21 19:48:53 -0600
commit6f6f28a22a479c80be7bb99cfdea4244cb667194 (patch)
tree88716418433148a2fd60613621e314a8349ec8e3 /config.go
parent1f0a18a0a8e21a831dbc002b8b4110298739b875 (diff)
minor fixupsv0.0.7
Diffstat (limited to 'config.go')
-rw-r--r--config.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/config.go b/config.go
index 03c81c5..cf41cbe 100644
--- a/config.go
+++ b/config.go
@@ -81,14 +81,24 @@ func (m *Machine) ConfigLoad() error {
hostname, _ := os.Hostname()
fname := hostname + ".pb"
- if data, err := m.loadFile(fname); err == nil {
+ var data []byte
+ var err error
+ if data, err = loadFile(fname); err != nil {
+ // something went wrong loading the file
+ return err
+ }
+
+ if data != nil {
if err = proto.Unmarshal(data, m); err != nil {
log.Warn("broken zookeeper.pb config file", fname)
return err
}
- } else {
- return err
+ return nil
}
+
+ m.Hostname = hostname
+ m.Distro = detectDistro()
+ m.initPackages()
return nil
}
@@ -97,6 +107,12 @@ func loadFile(filename string) ([]byte, error) {
p := filepath.Join(homeDir, ".config/zookeeper")
fullname := filepath.Join(p, filename)
data, err := os.ReadFile(fullname)
+ if errors.Is(err, os.ErrNotExist) {
+ // if file does not exist, just return nil. this
+ // will cause ConfigLoad() to try the next config file like "forge.text"
+ // because the user might want to edit the .config by hand
+ return nil, nil
+ }
if err != nil {
// log.Info("open config file :", err)
return nil, err