Skip to content

Commit 0c33f73

Browse files
committed
BUG/MEDIUM: reload_agent: create backups dir if it does not exist
1 parent 0bfca6f commit 0c33f73

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

haproxy/reload_agent.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"time"
3030

3131
"github.com/google/renameio"
32+
"github.com/haproxytech/client-native/v4/misc"
3233
"github.com/haproxytech/client-native/v4/models"
3334
"github.com/haproxytech/dataplaneapi/log"
3435
)
@@ -105,7 +106,9 @@ func NewReloadAgent(params ReloadAgentParams) (*ReloadAgent, error) {
105106
}
106107
ra.delay = params.Delay
107108

108-
ra.setLkgPath(params.ConfigFile, params.BackupDir)
109+
if err := ra.setLkgPath(params.ConfigFile, params.BackupDir); err != nil {
110+
return nil, err
111+
}
109112

110113
// create last known good file, assume it is valid when starting
111114
if err := copyFile(ra.configFile, ra.lkgConfigFile); err != nil {
@@ -117,12 +120,18 @@ func NewReloadAgent(params ReloadAgentParams) (*ReloadAgent, error) {
117120
return ra, nil
118121
}
119122

120-
func (ra *ReloadAgent) setLkgPath(configFile, path string) {
123+
func (ra *ReloadAgent) setLkgPath(configFile, path string) error {
121124
if path != "" {
125+
var err error
126+
path, err = misc.CheckOrCreateWritableDirectory(path)
127+
if err != nil {
128+
return err
129+
}
122130
ra.lkgConfigFile = fmt.Sprintf("%s/%s.lkg", path, filepath.Base(configFile))
123-
return
131+
return nil
124132
}
125133
ra.lkgConfigFile = configFile + ".lkg"
134+
return nil
126135
}
127136

128137
func (ra *ReloadAgent) handleReload(id string) (string, error) {

0 commit comments

Comments
 (0)