]> 127.0.0.1 Git - part/.git/commitdiff
20
authorqydysky <qydysky@foxmail.com>
Sat, 1 Aug 2020 00:24:57 +0000 (08:24 +0800)
committerqydysky <qydysky@foxmail.com>
Sat, 1 Aug 2020 00:24:57 +0000 (08:24 +0800)
CheckFile.go
Lock.go

index 03e6c0390b1ae53678b7100715087db52b9cd4a7..4592477c2b8192320694bf2f1331a3bbd1071f77 100644 (file)
@@ -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 eaf8a2f4d0502a7ddd7a271ce6242787debcdfe8..780ed8d2f5fe258dba937288da306ea6be2696de 100644 (file)
--- 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{