mirror of
https://github.com/beego/bee.git
synced 2024-12-22 20:20:49 +00:00
Revert "Backup only when content changes"
This reverts commit f601e441f3
.
This commit is contained in:
parent
0a2c7f0c57
commit
cbaa437ead
@ -6,8 +6,6 @@ import (
|
|||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/flosch/pongo2"
|
"github.com/flosch/pongo2"
|
||||||
"github.com/smartwalle/pongo2render"
|
"github.com/smartwalle/pongo2render"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"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)
|
beeLogger.Log.Fatalf("Could not create the %s render tmpl: %s", name, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = os.Stat(r.Descriptor.DstPath)
|
err = r.write(r.FlushFile, buf)
|
||||||
var orgContent []byte
|
if err != nil {
|
||||||
if err == nil {
|
beeLogger.Log.Fatalf("Could not create file: %s", err)
|
||||||
if org, err := os.OpenFile(r.Descriptor.DstPath, os.O_RDONLY, 0666); err == nil {
|
return
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
beeLogger.Log.Infof("create file '%s' from %s", r.FlushFile, r.PackageName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package beegopro
|
package beegopro
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/beego/bee/internal/pkg/utils"
|
"github.com/beego/bee/internal/pkg/utils"
|
||||||
@ -11,7 +10,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -190,41 +188,3 @@ func getModelType(orm string) (inputType, goType, mysqlType, tag string) {
|
|||||||
}
|
}
|
||||||
return
|
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