fix: ensure the configuration path exists (#19)

This commit is contained in:
UUBulb 2024-11-25 20:18:30 +08:00 committed by GitHub
parent 626a7d6059
commit 238ec25314
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,6 +2,7 @@ package model
import (
"os"
"path/filepath"
"strconv"
"strings"
@ -131,5 +132,11 @@ func (c *Config) Save() error {
if err != nil {
return err
}
dir := filepath.Dir(c.filePath)
if err := os.MkdirAll(dir, 0755); err != nil {
return err
}
return os.WriteFile(c.filePath, data, 0600)
}