diff --git a/db.go b/db.go index 5b1c213..dd3fd29 100644 --- a/db.go +++ b/db.go @@ -43,11 +43,10 @@ type WikiData struct { } func hasPassword(title string) (bool, error) { - Open(RuntimeArgs.DatabaseLocation) - defer Close() title = strings.ToLower(title) if !open { - return false, fmt.Errorf("db must be opened before loading") + Open(RuntimeArgs.DatabaseLocation) + defer Close() } hasPassword := false err := db.View(func(tx *bolt.Tx) error { @@ -126,11 +125,10 @@ func getCurrentText(title string, version int) (string, []versionsInfo, bool, ti } func (p *WikiData) load(title string) error { - Open(RuntimeArgs.DatabaseLocation) - defer Close() title = strings.ToLower(title) if !open { - return fmt.Errorf("db must be opened before loading!") + Open(RuntimeArgs.DatabaseLocation) + defer Close() } err := db.View(func(tx *bolt.Tx) error { var err error @@ -162,10 +160,9 @@ func (p *WikiData) load(title string) error { } func (p *WikiData) save(newText string) error { - Open(RuntimeArgs.DatabaseLocation) - defer Close() if !open { - return fmt.Errorf("db must be opened before saving") + Open(RuntimeArgs.DatabaseLocation) + defer Close() } err := db.Update(func(tx *bolt.Tx) error { bucket, err := tx.CreateBucketIfNotExists([]byte("datas")) diff --git a/main.go b/main.go index f9a128e..09358bf 100644 --- a/main.go +++ b/main.go @@ -61,9 +61,7 @@ Options:`) if *dumpDataset { fmt.Println("Dumping data to 'dump' folder...") - Open(RuntimeArgs.DatabaseLocation) dumpEverything() - Close() os.Exit(1) } @@ -87,7 +85,7 @@ Options:`) panic(err) } Close() - + // Default page aboutFile, _ := ioutil.ReadFile(path.Join(RuntimeArgs.SourcePath, "templates/aboutpage.md")) p := WikiData{"help", "", []string{}, []string{}, false}