基于serf的数据库同步模块库
chenshijun
2019-10-12 fc65716cb14d829c5ad9f79aa909ec0564eea2bd
判断SnapshotPath合法性
1个文件已修改
27 ■■■■■ 已修改文件
config.go 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
config.go
@@ -19,7 +19,10 @@
import (
    "fmt"
    "net"
    "os"
    "strconv"
    "strings"
    //"github.com/apache/servicecomb-service-center/syncer/pkg/utils"
    "github.com/hashicorp/memberlist"
    "github.com/hashicorp/serf/cmd/serf/command/agent"
@@ -88,6 +91,28 @@
    return nil
}
func isFileRightful(filePath string) bool {
    if filePath != "" {
        _, err := os.Stat(filePath)
        if err != nil && os.IsNotExist(err) {
            pos := strings.LastIndex(filePath, "/")
            if pos != -1 {
                filePath = filePath[0:pos]
            }
            _, err = os.Stat(filePath)
            if err == nil || !os.IsNotExist(err) {
                return true
            } else {
                return false
            }
        } else {
            return false
        }
    }
    return false
}
// convertToSerf convert Config to serf.Config
func (c *Config) convertToSerf(snapshotPath string) (*serf.Config, error) {
    serfConf := serf.DefaultConfig()
@@ -124,7 +149,7 @@
    }
    c.SnapshotPath = SnapshotPathDefault
    if snapshotPath != "" {
    if isFileRightful(snapshotPath) {
        c.SnapshotPath = snapshotPath
    }