From d1e813f4c1025b2d91cf96969bba107b29cc1d4d Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Wed, 18 Dec 2024 20:51:29 +0100 Subject: [PATCH] fix #4: mkdir only when needed --- app/db.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/db.go b/app/db.go index 450a3d1..69d07a8 100644 --- a/app/db.go +++ b/app/db.go @@ -37,16 +37,16 @@ type DbTag struct { const BucketData string = "data" 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 } 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) if err != nil { return err