mirror of
https://github.com/beego/bee.git
synced 2025-06-26 19:10:19 +00:00
Only contents in "CompareExcept" are excluded during comparison
This commit is contained in:
@ -80,11 +80,7 @@ func (c *RenderFile) write(filename string, buf []byte) (err error) {
|
||||
}
|
||||
|
||||
func isNeedOverwrite(fileName string) (flag bool) {
|
||||
seg := "//"
|
||||
ext := filepath.Ext(fileName)
|
||||
if ext == ".sql" {
|
||||
seg = "--"
|
||||
}
|
||||
seg := GetSeg(filepath.Ext(fileName))
|
||||
|
||||
f, err := os.Open(fileName)
|
||||
if err != nil {
|
||||
@ -190,21 +186,12 @@ func getModelType(orm string) (inputType, goType, mysqlType, tag string) {
|
||||
return
|
||||
}
|
||||
|
||||
func FileContentChange(org,new []byte) bool {
|
||||
func FileContentChange(org,new []byte, seg string) bool {
|
||||
if len(org) == 0 {
|
||||
return true
|
||||
}
|
||||
var orgContent,newContent string
|
||||
for i, s := range strings.Split(string(org), "\n") {
|
||||
if i > 1 {
|
||||
orgContent += s
|
||||
}
|
||||
}
|
||||
for i, s := range strings.Split(string(new), "\n") {
|
||||
if i > 1 {
|
||||
newContent += s
|
||||
}
|
||||
}
|
||||
orgContent := GetFilterContent(string(org),seg)
|
||||
newContent := GetFilterContent(string(org),string(new))
|
||||
orgMd5 := md5.Sum([]byte(orgContent))
|
||||
newMd5:= md5.Sum([]byte(newContent))
|
||||
if orgMd5 != newMd5 {
|
||||
@ -212,4 +199,30 @@ func FileContentChange(org,new []byte) bool {
|
||||
}
|
||||
beeLogger.Log.Infof("File has no change in the content")
|
||||
return false
|
||||
}
|
||||
|
||||
func GetFilterContent(content string, seg string) string {
|
||||
res := ""
|
||||
for _, s := range strings.Split(content, "\n") {
|
||||
s = strings.TrimSpace(strings.TrimPrefix(s, seg))
|
||||
var have = false
|
||||
for _,except := range CompareExcept{
|
||||
if strings.HasPrefix(s, except) {
|
||||
have = true
|
||||
}
|
||||
}
|
||||
if !have {
|
||||
res += s
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func GetSeg(ext string) string {
|
||||
switch ext {
|
||||
case ".sql":
|
||||
return "--"
|
||||
default:
|
||||
return "//"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user