Commit 50df2b78 authored by Armin Braun's avatar Armin Braun Committed by Felix Lange

console: create datadir at startup (#15700)

Fixes #15672 by creating the datadir when creating the
console. This prevents failing to save the history if no datadir
exists.
parent c786f753
...@@ -92,6 +92,9 @@ func New(config Config) (*Console, error) { ...@@ -92,6 +92,9 @@ func New(config Config) (*Console, error) {
printer: config.Printer, printer: config.Printer,
histPath: filepath.Join(config.DataDir, HistoryFile), histPath: filepath.Join(config.DataDir, HistoryFile),
} }
if err := os.MkdirAll(config.DataDir, 0700); err != nil {
return nil, err
}
if err := console.init(config.Preload); err != nil { if err := console.init(config.Preload); err != nil {
return nil, err return nil, err
} }
...@@ -423,7 +426,7 @@ func (c *Console) Execute(path string) error { ...@@ -423,7 +426,7 @@ func (c *Console) Execute(path string) error {
return c.jsre.Exec(path) return c.jsre.Exec(path)
} }
// Stop cleans up the console and terminates the runtime envorinment. // Stop cleans up the console and terminates the runtime environment.
func (c *Console) Stop(graceful bool) error { func (c *Console) Stop(graceful bool) error {
if err := ioutil.WriteFile(c.histPath, []byte(strings.Join(c.history, "\n")), 0600); err != nil { if err := ioutil.WriteFile(c.histPath, []byte(strings.Join(c.history, "\n")), 0600); err != nil {
return err return err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment