OSDN Git Service

fix dir is not exist (#368)
authorwyjDoraemon <46176410+wyjDoraemon@users.noreply.github.com>
Tue, 30 Jul 2019 08:27:12 +0000 (16:27 +0800)
committerPaladz <yzhu101@uottawa.ca>
Tue, 30 Jul 2019 08:27:12 +0000 (16:27 +0800)
* fix dir is not exist

* fix

log/log.go

index ebd979f..c766483 100644 (file)
@@ -30,7 +30,7 @@ func InitLogFile(config *config.Config) error {
 
        hook := newBtmHook(logPath)
        logrus.AddHook(hook)
 
        hook := newBtmHook(logPath)
        logrus.AddHook(hook)
-       logrus.SetOutput(ioutil.Discard)//控制台不输出
+       logrus.SetOutput(ioutil.Discard) //控制台不输出
        fmt.Printf("all logs are output in the %s directory\n", logPath)
        return nil
 }
        fmt.Printf("all logs are output in the %s directory\n", logPath)
        return nil
 }
@@ -74,13 +74,15 @@ func (hook *BtmHook) ioWrite(entry *logrus.Entry) error {
 
 func clearLockFiles(logPath string) error {
        files, err := ioutil.ReadDir(logPath)
 
 func clearLockFiles(logPath string) error {
        files, err := ioutil.ReadDir(logPath)
-       if err != nil {
+       if os.IsNotExist(err) {
+               return nil
+       }else if err != nil {
                return err
        }
 
        for _, file := range files {
                if ok := strings.HasSuffix(file.Name(), "_lock"); ok {
                return err
        }
 
        for _, file := range files {
                if ok := strings.HasSuffix(file.Name(), "_lock"); ok {
-                       if err := os.Remove(filepath.Join(logPath, file.Name()));err!=nil{
+                       if err := os.Remove(filepath.Join(logPath, file.Name())); err != nil {
                                return err
                        }
                }
                                return err
                        }
                }