From 8474b79cf1966bff5868dc300557d765a506670a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Gul=C3=A1csi?= Date: Mon, 2 Oct 2017 13:55:48 +0200 Subject: [PATCH 1/2] migrate: return on error (esp. Save) --- migrate.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/migrate.go b/migrate.go index 0a03621..c4f314e 100755 --- a/migrate.go +++ b/migrate.go @@ -7,8 +7,14 @@ import ( ) func migrate(pathToOldData, pathToData string) error { - files, _ := ioutil.ReadDir(pathToOldData) + files, err := ioutil.ReadDir(pathToOldData) + if len(files) == 0 { + return err + } for _, f := range files { + if f.Mode().IsDir() { + continue + } fmt.Printf("Migrating %s", f.Name()) p := Open(f.Name()) bData, err := ioutil.ReadFile(path.Join(pathToOldData, f.Name())) @@ -19,7 +25,9 @@ func migrate(pathToOldData, pathToData string) error { if err != nil { return err } - p.Save() + if err = p.Save(); err != nil { + return err + } } return nil } From b83e3fd52e4a0f9ff93929fdd8d64780642ef290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Gul=C3=A1csi?= Date: Mon, 2 Oct 2017 13:58:39 +0200 Subject: [PATCH 2/2] precompile regexp --- page.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/page.go b/page.go index f541d02..8ff9881 100755 --- a/page.go +++ b/page.go @@ -76,6 +76,8 @@ func (p *Page) Update(newText string) error { return p.Save() } +var rBracketPage = regexp.MustCompile(`\[\[(.*?)\]\]`) + func (p *Page) Render() { if p.IsEncrypted { p.RenderedPage = "" + p.Text.GetCurrent() + "" @@ -83,9 +85,8 @@ func (p *Page) Render() { } // Convert [[page]] to [page](/page/view) - r, _ := regexp.Compile("\\[\\[(.*?)\\]\\]") currentText := p.Text.GetCurrent() - for _, s := range r.FindAllString(currentText, -1) { + for _, s := range rBracketPage.FindAllString(currentText, -1) { currentText = strings.Replace(currentText, s, "["+s[2:len(s)-2]+"](/"+s[2:len(s)-2]+"/view)", 1) } p.Text.Update(currentText)