|
@@ -88,15 +88,6 @@ func InitLocalWorkSpace(conn *websocket.Conn,userName,projectName string) (error |
|
|
|
|
|
|
|
|
log.Println("切换本地工作目录至 "+projectPath) |
|
|
log.Println("切换本地工作目录至 "+projectPath) |
|
|
|
|
|
|
|
|
err = filepath.Walk(projectPath,watchWalkfunc) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
config.GobalWatchChannelMap[projectPath]=make(chan string,100) |
|
|
|
|
|
log.Println(projectPath+"添加文件监控") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := conn.WriteMessage(websocket.TextMessage, []byte(fmt.Sprint(projectPath))); err != nil { |
|
|
if err := conn.WriteMessage(websocket.TextMessage, []byte(fmt.Sprint(projectPath))); err != nil { |
|
|
log.Println(err) |
|
|
log.Println(err) |
|
|
return err |
|
|
return err |
|
@@ -112,6 +103,7 @@ func watchWalkfunc(filePath string, info os.FileInfo, err error) error { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if info.IsDir()==true{ |
|
|
if info.IsDir()==true{ |
|
|
|
|
|
//config.GobalWatch.Remove(filePath) |
|
|
err = config.GobalWatch.Add(filePath) |
|
|
err = config.GobalWatch.Add(filePath) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Println(err) |
|
|
log.Println(err) |
|
@@ -512,12 +504,14 @@ func UploadCommand(conn *websocket.Conn,absolutePath,fileName,projectName,dir,cu |
|
|
} |
|
|
} |
|
|
log.Println("引导节点文件备份成功") |
|
|
log.Println("引导节点文件备份成功") |
|
|
|
|
|
|
|
|
//本地文件夹拷贝 |
|
|
|
|
|
err = sh.Get(prog.Hash,fmt.Sprint((absoluteDir+"\\"+fileName))) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//文件不存在则进行本地文件夹拷贝 |
|
|
|
|
|
if !fileExist(fmt.Sprint((absoluteDir+"\\"+fileName))) { |
|
|
|
|
|
err = sh.Get(prog.Hash,fmt.Sprint((absoluteDir+"\\"+fileName))) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//记录历史 |
|
|
//记录历史 |
|
|
filenameall := path.Base(fileName) |
|
|
filenameall := path.Base(fileName) |
|
@@ -777,31 +771,41 @@ func fileExist(path string) bool { |
|
|
获取本地文件列表 |
|
|
获取本地文件列表 |
|
|
*/ |
|
|
*/ |
|
|
func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
//getLocalFileListDir := fmt.Sprint(config.LocalWorkSpaceDir+gobalLoginUserName+"\\"+projectName) |
|
|
|
|
|
log.Println("切换文件列表:"+getLocalFileListDir) |
|
|
|
|
|
|
|
|
getLocalFileListDir = fmt.Sprint(config.LocalWorkSpaceDir+gobalLoginUserName+"\\"+projectName) |
|
|
|
|
|
projectPath := getLocalFileListDir |
|
|
|
|
|
log.Println("切换文件列表:"+projectPath) |
|
|
keyPrefix := gobalLoginUserName+"\\"+projectName+"\\" |
|
|
keyPrefix := gobalLoginUserName+"\\"+projectName+"\\" |
|
|
|
|
|
|
|
|
|
|
|
//添加监控 |
|
|
|
|
|
err := filepath.Walk(projectPath,watchWalkfunc) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
//初始化通道 |
|
|
|
|
|
if config.GobalWatchChannelMap[projectPath] != nil { |
|
|
|
|
|
close(config.GobalWatchChannelMap[projectPath]) |
|
|
|
|
|
} |
|
|
|
|
|
config.GobalWatchChannelMap[projectPath]=make(chan string,100) |
|
|
|
|
|
log.Println(projectPath+"添加文件监控") |
|
|
|
|
|
log.Println(config.GobalWatchChannelMap[projectPath]) |
|
|
|
|
|
|
|
|
//定期校验缓存的本地文件状态 |
|
|
//定期校验缓存的本地文件状态 |
|
|
go func() { |
|
|
|
|
|
for true { |
|
|
|
|
|
time.Sleep(time.Duration(5)*time.Minute) |
|
|
|
|
|
dataMap,err := etcdclient.QueryWithPrefix(keyPrefix) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
if dataMap!=nil && len(dataMap)>0{ |
|
|
|
|
|
for k,_ := range dataMap { |
|
|
|
|
|
if !fileExist(config.LocalWorkSpaceDir+k){ |
|
|
|
|
|
err = etcdclient.DeleteWithPrefix(k) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
dataMapa,err := etcdclient.QueryWithPrefix(keyPrefix) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
} |
|
|
|
|
|
if dataMapa!=nil && len(dataMapa)>0{ |
|
|
|
|
|
for k,_ := range dataMapa { |
|
|
|
|
|
if !fileExist(config.LocalWorkSpaceDir+k){ |
|
|
|
|
|
err = etcdclient.DeleteWithPrefix(k) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println(err) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}() |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//优先etcd查询 |
|
|
//优先etcd查询 |
|
|
dataMap,err := etcdclient.QueryWithPrefix(keyPrefix) |
|
|
dataMap,err := etcdclient.QueryWithPrefix(keyPrefix) |
|
@@ -860,8 +864,10 @@ func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ch :=config.GobalWatchChannelMap[getLocalFileListDir] |
|
|
|
|
|
for actionAndModifyFilePathStr :=range ch { |
|
|
|
|
|
|
|
|
//ch :=config.GobalWatchChannelMap[getLocalFileListDir] |
|
|
|
|
|
log.Println(config.GobalWatchChannelMap[getLocalFileListDir]) |
|
|
|
|
|
for actionAndModifyFilePathStr :=range config.GobalWatchChannelMap[getLocalFileListDir] { |
|
|
|
|
|
log.Println(actionAndModifyFilePathStr) |
|
|
actionAndModifyFilePath := strings.Split(actionAndModifyFilePathStr,";") |
|
|
actionAndModifyFilePath := strings.Split(actionAndModifyFilePathStr,";") |
|
|
if actionAndModifyFilePath[0]=="remove"{ |
|
|
if actionAndModifyFilePath[0]=="remove"{ |
|
|
k := strings.Replace(actionAndModifyFilePath[1],config.LocalWorkSpaceDir,"",1) |
|
|
k := strings.Replace(actionAndModifyFilePath[1],config.LocalWorkSpaceDir,"",1) |
|
@@ -948,6 +954,8 @@ func sendFileListFromEtcd(keyPrefix,projectName string,conn *websocket.Conn) err |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
return nil |
|
|
return nil |
|
|
|
|
|
}else{ |
|
|
|
|
|
log.Println("未查询到数据,keyPrefix:"+keyPrefix+",projectName:"+projectName) |
|
|
} |
|
|
} |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|