From cbaa437ead78682dba0500006dcb055a10296a1c Mon Sep 17 00:00:00 2001 From: askuy Date: Mon, 27 Jul 2020 13:11:14 +0800 Subject: [PATCH] Revert "Backup only when content changes" This reverts commit f601e441f3be2695063fd335901ab4e20d2e0828. --- internal/app/module/beegopro/render.go | 26 ++++------------- internal/app/module/beegopro/util.go | 40 -------------------------- 2 files changed, 5 insertions(+), 61 deletions(-) diff --git a/internal/app/module/beegopro/render.go b/internal/app/module/beegopro/render.go index 64c52fc..f2e49c3 100644 --- a/internal/app/module/beegopro/render.go +++ b/internal/app/module/beegopro/render.go @@ -6,8 +6,6 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/flosch/pongo2" "github.com/smartwalle/pongo2render" - "io/ioutil" - "os" "path" "path/filepath" ) @@ -116,24 +114,10 @@ func (r *RenderFile) Exec(name string) { beeLogger.Log.Fatalf("Could not create the %s render tmpl: %s", name, err) return } - _, err = os.Stat(r.Descriptor.DstPath) - var orgContent []byte - if err == nil { - if org, err := os.OpenFile(r.Descriptor.DstPath, os.O_RDONLY, 0666); err == nil { - defer org.Close() - orgContent,_ = ioutil.ReadAll(org) - } else { - beeLogger.Log.Infof("file err %s", err) - } - } - // Replace or create when content changes - if len(orgContent) == 0 || FileContentChange(string(orgContent),buf) { - err = r.write(r.FlushFile, buf) - if err != nil { - beeLogger.Log.Fatalf("Could not create file: %s", err) - return - } - beeLogger.Log.Infof("create file '%s' from %s", r.FlushFile, r.PackageName) + err = r.write(r.FlushFile, buf) + if err != nil { + beeLogger.Log.Fatalf("Could not create file: %s", err) + return } + beeLogger.Log.Infof("create file '%s' from %s", r.FlushFile, r.PackageName) } - diff --git a/internal/app/module/beegopro/util.go b/internal/app/module/beegopro/util.go index 2cbfe23..e1491bd 100644 --- a/internal/app/module/beegopro/util.go +++ b/internal/app/module/beegopro/util.go @@ -1,7 +1,6 @@ package beegopro import ( - "crypto/md5" "errors" "fmt" "github.com/beego/bee/internal/pkg/utils" @@ -11,7 +10,6 @@ import ( "os" "path" "path/filepath" - "regexp" "strings" "time" ) @@ -190,41 +188,3 @@ func getModelType(orm string) (inputType, goType, mysqlType, tag string) { } return } - -func FileContentChange(org,new string) bool { - if org == "" { - return false - } - var orgContent,newContent string - jump := false - // expect tab character and blank space and "import(***)" - reg := regexp.MustCompile("\\s+") - for i, s := range strings.Split(org, "\n") { - if s == "import (" { - jump = true - } - if jump && s == ")" { - jump = false - } - if i > 2 && !jump { - orgContent += reg.ReplaceAllString(s, "") - } - } - for i, s := range strings.Split(new, "\n") { - if s == "import (" { - jump = true - } - if jump && s == ")" { - jump = false - } - if i > 2 && !jump { - newContent += reg.ReplaceAllString(s, "") - } - } - orgMd5 := md5.Sum([]byte(orgContent)) - newMd5:= md5.Sum([]byte(newContent)) - if orgMd5 != newMd5 { - return true - } - return false -} \ No newline at end of file