mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Check if opened
Former-commit-id: a9ee6c19c060ff6323c9657cb90f2b166a4f7103 [formerly d75dba0b429e79ac8d417dcf044496f8d735d803] [formerly 9413872d5aecf982e873fcf43bf87cec2acf3e98 [formerly 3ef10c9466
]]
Former-commit-id: 7513366547dbac6a0778dbb49f1446092fc59842 [formerly f1f5d9eb16be383430f83b397c40c65ae0551ee9]
Former-commit-id: bd73123413245683c3a90e6ae46884fa901f6e35
This commit is contained in:
parent
bb0f0845a5
commit
17f04a167f
15
db.go
15
db.go
@ -43,11 +43,10 @@ type WikiData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func hasPassword(title string) (bool, error) {
|
func hasPassword(title string) (bool, error) {
|
||||||
Open(RuntimeArgs.DatabaseLocation)
|
|
||||||
defer Close()
|
|
||||||
title = strings.ToLower(title)
|
title = strings.ToLower(title)
|
||||||
if !open {
|
if !open {
|
||||||
return false, fmt.Errorf("db must be opened before loading")
|
Open(RuntimeArgs.DatabaseLocation)
|
||||||
|
defer Close()
|
||||||
}
|
}
|
||||||
hasPassword := false
|
hasPassword := false
|
||||||
err := db.View(func(tx *bolt.Tx) error {
|
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 {
|
func (p *WikiData) load(title string) error {
|
||||||
Open(RuntimeArgs.DatabaseLocation)
|
|
||||||
defer Close()
|
|
||||||
title = strings.ToLower(title)
|
title = strings.ToLower(title)
|
||||||
if !open {
|
if !open {
|
||||||
return fmt.Errorf("db must be opened before loading!")
|
Open(RuntimeArgs.DatabaseLocation)
|
||||||
|
defer Close()
|
||||||
}
|
}
|
||||||
err := db.View(func(tx *bolt.Tx) error {
|
err := db.View(func(tx *bolt.Tx) error {
|
||||||
var err error
|
var err error
|
||||||
@ -162,10 +160,9 @@ func (p *WikiData) load(title string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *WikiData) save(newText string) error {
|
func (p *WikiData) save(newText string) error {
|
||||||
Open(RuntimeArgs.DatabaseLocation)
|
|
||||||
defer Close()
|
|
||||||
if !open {
|
if !open {
|
||||||
return fmt.Errorf("db must be opened before saving")
|
Open(RuntimeArgs.DatabaseLocation)
|
||||||
|
defer Close()
|
||||||
}
|
}
|
||||||
err := db.Update(func(tx *bolt.Tx) error {
|
err := db.Update(func(tx *bolt.Tx) error {
|
||||||
bucket, err := tx.CreateBucketIfNotExists([]byte("datas"))
|
bucket, err := tx.CreateBucketIfNotExists([]byte("datas"))
|
||||||
|
4
main.go
4
main.go
@ -61,9 +61,7 @@ Options:`)
|
|||||||
|
|
||||||
if *dumpDataset {
|
if *dumpDataset {
|
||||||
fmt.Println("Dumping data to 'dump' folder...")
|
fmt.Println("Dumping data to 'dump' folder...")
|
||||||
Open(RuntimeArgs.DatabaseLocation)
|
|
||||||
dumpEverything()
|
dumpEverything()
|
||||||
Close()
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +85,7 @@ Options:`)
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
Close()
|
Close()
|
||||||
|
|
||||||
// Default page
|
// Default page
|
||||||
aboutFile, _ := ioutil.ReadFile(path.Join(RuntimeArgs.SourcePath, "templates/aboutpage.md"))
|
aboutFile, _ := ioutil.ReadFile(path.Join(RuntimeArgs.SourcePath, "templates/aboutpage.md"))
|
||||||
p := WikiData{"help", "", []string{}, []string{}, false}
|
p := WikiData{"help", "", []string{}, []string{}, false}
|
||||||
|
Loading…
Reference in New Issue
Block a user