mirror of
https://codeberg.org/scip/anydb.git
synced 2025-12-17 04:20:59 +01:00
fix #4: mkdir only when needed
This commit is contained in:
12
app/db.go
12
app/db.go
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user