This commit is contained in:
Jeff Carr 2025-09-10 15:05:22 -05:00
parent 5f886d7c07
commit 2943d44b4a
1 changed files with 10 additions and 20 deletions

30
save.go
View File

@ -25,14 +25,21 @@ func ConfigSave(pb proto.Message) error {
return err return err
} }
dir, name := filepath.Split(fullname)
if name == "" {
return fmt.Errorf("filename was blank")
}
err = os.MkdirAll(dir, os.ModePerm)
if err != nil {
return err
}
log.Infof("ConfigSave() filename=%s %d\n", fullname, len(data)) log.Infof("ConfigSave() filename=%s %d\n", fullname, len(data))
return configWrite(fullname, data) return configWrite(fullname, data)
} }
func configWrite(fullname string, data []byte) error { func configWrite(fullname string, data []byte) error {
if _, base := filepath.Split(fullname); base == "" {
return fmt.Errorf("--config option not set")
}
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
defer cfgfile.Close() defer cfgfile.Close()
if err != nil { if err != nil {
@ -44,7 +51,6 @@ func configWrite(fullname string, data []byte) error {
} }
/* /*
func (e *Events) Save() { func (e *Events) Save() {
var fullname string var fullname string
base, _ := filepath.Split(argv.Config) base, _ := filepath.Split(argv.Config)
@ -58,20 +64,4 @@ func (e *Events) Save() {
log.Info("proto.Marshal() worked len", len(data)) log.Info("proto.Marshal() worked len", len(data))
configWrite(fullname, data) configWrite(fullname, data)
} }
func (m *Portmaps) configWrite(fullname string, data []byte) error {
if _, base := filepath.Split(fullname); base == "" {
return fmt.Errorf("--config option not set")
}
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
defer cfgfile.Close()
if err != nil {
log.Warn("open config file :", err)
return err
}
cfgfile.Write(data)
return nil
}
*/ */