mirror of
https://github.com/beego/bee.git
synced 2024-11-21 13:40:53 +00:00
Revert "Backup only when content changes"
This reverts commit f601e441f3
.
This commit is contained in:
parent
0a2c7f0c57
commit
19d0116825
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user