fix #4: mkdir only when needed

This commit is contained in:
Thomas von Dein
2024-12-18 20:51:29 +01:00
parent d84e075a26
commit d1e813f4c1

View File

@@ -37,16 +37,16 @@ type DbTag struct {
const BucketData string = "data" const BucketData string = "data"
func New(file string, debug bool) (*DB, error) { func New(file string, debug bool) (*DB, error) {
if _, err := os.Stat(filepath.Dir(file)); os.IsNotExist(err) {
if err := os.MkdirAll(filepath.Dir(file), 0700); err != nil {
return nil, err
}
}
return &DB{Debug: debug, Dbfile: file}, nil return &DB{Debug: debug, Dbfile: file}, nil
} }
func (db *DB) Open() error { func (db *DB) Open() error {
if _, err := os.Stat(filepath.Dir(db.Dbfile)); os.IsNotExist(err) {
if err := os.MkdirAll(filepath.Dir(db.Dbfile), 0700); err != nil {
return err
}
}
b, err := bolt.Open(db.Dbfile, 0600, nil) b, err := bolt.Open(db.Dbfile, 0600, nil)
if err != nil { if err != nil {
return err return err