From 392687193d3973fec9a7dce3ce61a7b66788d415 Mon Sep 17 00:00:00 2001 From: qydysky Date: Mon, 27 Jul 2020 05:16:55 +0800 Subject: [PATCH] 7 --- CheckFile.go | 51 +++++++++++++++++++++++++++++++++++++++------------ Log.go | 8 ++++---- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/CheckFile.go b/CheckFile.go index 95bea46..c6c6d79 100644 --- a/CheckFile.go +++ b/CheckFile.go @@ -17,7 +17,7 @@ func Checkfile() *checkfile{ return &checkfile{} } -func (this *checkfile) Build(checkFile,checkDir,SplitString string) { +func (this *checkfile) Build(checkFile,root,checkDir,SplitString string,usemd5 bool) { v,_,_:=this.GetAllFile(checkDir) _checkFile := Filel { @@ -28,8 +28,18 @@ func (this *checkfile) Build(checkFile,checkDir,SplitString string) { Logf().I("checkFile Build:begin") + if usemd5 {_checkFile.Context += "UseMd5"} + + _checkFile.Context += SplitString + for _,value := range v { - _checkFile.Context += value + SplitString + if usemd5 { + md5, e := Md5().Md5File(value) + if e != nil {md5 = "00000000000000000000000000000000"} + _checkFile.Context += md5 + } + _checkFile.Context += value[len(root):] + _checkFile.Context += SplitString } File().FileWR(_checkFile) @@ -93,7 +103,7 @@ func (this *checkfile) GetFileSize(path string) int64 { return fileInfo.Size() } -func (this *checkfile) CheckList(checkFile,SplitString string)bool{ +func (this *checkfile) CheckList(checkFile,root,SplitString string)bool{ if checkFile == "" || SplitString == "" { Logf().E("[err]checkFile or SplitString has null.") @@ -132,21 +142,38 @@ func (this *checkfile) CheckList(checkFile,SplitString string)bool{ checkFileList=strings.Split(checkFileString,SplitString); - var returnVal bool = true - for _,value := range checkFileList { - if value!=""&&!this.IsExist(value) { - Logf().E("[err]checkFile:",value,"not exist!") - returnVal=false + var ( + returnVal bool = true + UseMd5 bool = strings.Contains(checkFileList[0], "UseMd5") + _value string + ) + + for _,value := range checkFileList[1:] { + if value == "" {continue} + + if UseMd5 {_value = root + value[32:]}else{_value = root + value} + + if !this.IsExist(_value) { + Logf().E("[err]checkFile:", _value, "not exist!") + returnVal = false }else{ - if runtime.GOOS!="windows" && strings.Contains(value,".run") { + if UseMd5 { + if md5,_ := Md5().Md5File(_value); value[:32] != md5 { + Logf().E("[err]checkFile:", _value, "no match!") + returnVal = false + } + } + + if runtime.GOOS != "windows" && strings.Contains(_value, ".run") { var want os.FileMode = 0700 - if !this.CheckFilePerm(value,want) { - Logf().E("[err]checkFile:",value,"no permission!") - returnVal=false + if !this.CheckFilePerm(_value, want) { + Logf().E("[err]checkFile:", _value, "no permission!") + returnVal = false } } // fmt.Println("[ok]checkFile:",checkDir+value) } + } if returnVal {Logf().I("[ok]checkFile: all file pass!")} Logf().I("===checkFile Check===") diff --git a/Log.go b/Log.go index 51aafd3..e3987dc 100644 --- a/Log.go +++ b/Log.go @@ -32,19 +32,19 @@ func (*logl) New(fileP string) { tracef = log.New(io.MultiWriter(file, os.Stdout), "TRACE: ", - log.Ldate|log.Ltime|log.Lshortfile) + log.Ldate|log.Ltime) infof = log.New(io.MultiWriter(file, os.Stdout), "INFO: ", - log.Ldate|log.Ltime|log.Lshortfile) + log.Ldate|log.Ltime) warningf = log.New(io.MultiWriter(file, os.Stdout), "WARNING: ", - log.Ldate|log.Ltime|log.Lshortfile) + log.Ldate|log.Ltime) errorf = log.New(io.MultiWriter(file, os.Stderr), "ERROR: ", - log.Ldate|log.Ltime|log.Lshortfile) + log.Ldate|log.Ltime) isinit = true } -- 2.39.2