]> 127.0.0.1 Git - part/.git/commitdiff
2
authorqydysky <qydysky@foxmail.com>
Sat, 25 Jul 2020 23:41:03 +0000 (07:41 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 26 Jul 2020 00:50:07 +0000 (08:50 +0800)
CheckFile.go
FileWR.go
Log.go

index ee88871262d7df7920642ab9bc5f8752b526e083..0c4d515c9dd2e58606519c1162537a4ae771547b 100644 (file)
@@ -18,84 +18,23 @@ func Checkfile() *checkfile{
 }
 
 func (this *checkfile) Build(checkFile,checkDir,SplitString string) {
-       v,_:=this.GetAllFile(checkDir)
-
+       
+       v,_,_:=this.GetAllFile(checkDir)
        _checkFile := Filel {
                File:checkFile,
                Write:true,
                Loc:0,
        }
 
-       fmt.Println("===checkFile Build===")
+       Logf().I("checkFile Build:begin")
 
        for _,value := range v {
-               _checkFile.Context += string(value) + SplitString
-               fmt.Print(value,"\r")
+               _checkFile.Context += value + SplitString
        }
        
        File().FileWR(_checkFile)
-       fmt.Println("===checkFile Build===")
-
-}
+       Logf().I("checkFile Build:ok")
 
-func (this *checkfile) Check(checkFile,checkDir,SplitString string) bool {
-       
-       if checkFile == "" || SplitString == "" {
-               fmt.Println("[err]checkFile or SplitString has null.")
-               return false
-       }
-       fmt.Println("===checkFile Check===")
-
-       var checkFileString string
-       var checkFileList []string 
-       if strings.Contains(checkFile,"https://") {
-               fmt.Println("[wait]checkFile: Getting checkfile...")
-
-               b,_,e := Reqf(ReqfVal {
-                       Url:checkFile,
-                       Timeout:6,
-            Retry:2,
-               })
-
-               if e != nil {
-                       fmt.Println("[err]checkFile:",checkFile,e)
-                       return false
-               }else{
-                       fmt.Println("[ok]checkFile: Get checkfile.")
-                       checkFileString = string(b)
-               }
-       }else{
-
-               checkFileString = File().FileWR(Filel {
-                       File:checkFile,
-                       Write:false,
-                       Loc:0,
-               })
-
-       }
-
-       checkFileList = strings.Split(checkFileString,SplitString);
-
-       var returnVal bool = true
-       for _,value := range checkFileList {
-               if value != "" && !this.IsExist(checkDir+value) {
-                       fmt.Println("[err]checkFile:", checkDir+value, "not exist!")
-                       returnVal = false
-               }else{
-                       if runtime.GOOS != "windows" && strings.Contains(value, ".run") {
-                               var want os.FileMode = 0700
-                               if ! this.CheckFilePerm(value,want) {
-                                       fmt.Println("[err]checkFile:", checkDir+value, "no permission!")
-                                       returnVal = false
-                               }
-                       }
-                       // fmt.Println("[ok]checkFile:",checkDir+value)
-               }
-       }
-       if returnVal {fmt.Println("[ok]checkFile: all file pass!")}
-       fmt.Println("===checkFile Check===")
-
-       return returnVal
 }
 
 func (this *checkfile) IsExist(f string) bool {
@@ -112,7 +51,7 @@ func (this *checkfile) IsOpen(f string) bool {
 
 func (this *checkfile) Checkfile(src string)(string,error){
 
-    str,err:=this.GetAllFile(src)
+    _,str,err:=this.GetAllFile(src)
 
     if err !=nil {return "",errors.New("获取文件列表错误!")}
 
@@ -120,21 +59,26 @@ func (this *checkfile) Checkfile(src string)(string,error){
 
 }
 
-func (this *checkfile) GetAllFile(pathname string) (string,error) {
+func (this *checkfile) GetAllFile(pathname string) ([]string,string,error) {
 
-    var returnVal string = ""
+    var (
+               returnVal string = ""
+               list []string
+       )
 
     rd, err := ioutil.ReadDir(pathname)
 
     for _, fi := range rd {
         if fi.IsDir() {
-            _returnVal,_:=this.GetAllFile(pathname + fi.Name() + "/")
-            returnVal+=_returnVal
+            _list, _returnVal, _:=this.GetAllFile(pathname + fi.Name() + "/")
+                       returnVal+=_returnVal
+                       list = append(list, _list...)
         } else {
-            returnVal+=pathname + fi.Name()
+                       returnVal+=pathname + fi.Name() + "\n"
+                       list = append(list, pathname + fi.Name())
         }
     }
-    return returnVal,err
+    return list,returnVal,err
 }
 
 func (this *checkfile) GetFileSize(path string) int64 {
index 12df737c5bdb30d79b95950c37c12b7f85f3cef9..3c086c4972ccd096b72bb1fd1129fcbdb25c8314 100644 (file)
--- a/FileWR.go
+++ b/FileWR.go
@@ -59,6 +59,8 @@ func (this *file) write(C Filel) string {
                Context string=C.Context
        )
 
+       this.NewPath(File)
+
        var Kind int 
        switch Loc {
                case 0:Kind=os.O_RDWR|os.O_EXCL|os.O_TRUNC
@@ -146,8 +148,6 @@ func (this *file) locfix(Loc int64,File string,fileObj *os.File)int64{
 }
 
 func (this *file) NewPath(filename string) error{
-       this.Lock()
-       defer this.Unlock()
 
        /*
                如果filename路径不存在,就新建它
diff --git a/Log.go b/Log.go
index 236914cc9bd208306103dff316bccb588eea8067..51aafd348dd712f5ffa49509c7845c35e9a99f95 100644 (file)
--- a/Log.go
+++ b/Log.go
@@ -50,18 +50,18 @@ func (*logl) New(fileP string) {
 }
 
 func (*logl) T(l ...string){
-       if !isinit {log.Fatalln("not New(file string) yet!");return}
+       if !isinit {log.Println("TRACE:",l);return}
        tracef.Println(l)
 }
 func (*logl) I(l ...string){
-       if !isinit {log.Fatalln("not New(file string) yet!");return}
+       if !isinit {log.Println("INFO:",l);return}
        infof.Println(l)
 }
 func (*logl) W(l ...string){
-       if !isinit {log.Fatalln("not New(file string) yet!");return}
+       if !isinit {log.Println("WARNING:",l);return}
        warningf.Println(l)
 }
 func (*logl) E(l ...string){
-       if !isinit {log.Fatalln("not New(file string) yet!");return}
+       if !isinit {log.Println("ERROR:",l);return}
        errorf.Println(l)
 }
\ No newline at end of file