From: qydysky Date: Sat, 1 Aug 2020 00:24:57 +0000 (+0800) Subject: 20 X-Git-Tag: v0.0.2~68 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=47eb172b8da32adc60fe676438b8b3f138737083;p=part%2F.git 20 --- diff --git a/CheckFile.go b/CheckFile.go index 03e6c03..4592477 100644 --- a/CheckFile.go +++ b/CheckFile.go @@ -185,6 +185,8 @@ func (this *checkfile) CheckList(checkFile,root,SplitString string)bool{ func (this *checkfile) GetFileModTime(path string) (error,int64) { + if !this.IsExist(path) {return errors.New("not exist"),time.Now().Unix()} + f, err := os.Open(path) if err != nil { fmt.Println("open file error") diff --git a/Lock.go b/Lock.go index eaf8a2f..780ed8d 100644 --- a/Lock.go +++ b/Lock.go @@ -24,14 +24,17 @@ func (l *lock) Start(filePath string,timeout int64) error { l.Lock() defer l.Unlock() - if e,t := Checkfile().GetFileModTime(filePath); e != nil || time.Now().Unix() - t <= lock_timeout { - Logf().E(e.Error(),"or still alive") - return errors.New("still alive") + if Checkfile().IsExist(filePath) { + if e,t := Checkfile().GetFileModTime(filePath); e != nil || time.Now().Unix() - t <= lock_timeout { + Logf().E(e.Error(),"or still alive") + return errors.New("still alive") + } } + lock_file = filePath lock_timeout = timeout - + go func(){ for lock_file != "" { File().FileWR(Filel{