コード例 #1
0
ファイル: fs.go プロジェクト: izouxv/raftX
func (fs *Fs) notifyValueChange(notify bool, key string, value string, verb Verb) {
	if !notify {
		return
	}
	//return

	for patPath, ips := range fs.watch_Path_Ip_Tag {
		matchOk := false
		if patPath == key {
			matchOk = true
		} else {
			glob, err := CompileGlob(patPath)
			if err != nil {
				fmt.Printf("getFile error: path: %v\n", patPath)
				return
			}
			matchOk = glob.Match(key)
		}
		//matchOk = true

		if matchOk {
			for ip, tag := range ips {
				fs.notify(key, value, tag, verb, ip, patPath)
			}
		}
	}

	for patPath, ips := range fs.watchImmediate_Path_Ip_Tag {
		matchOk := false
		if patPath == key {
			matchOk = true
		} else {
			glob, err := CompileGlob(patPath)
			if err != nil {
				fmt.Printf("getFile error: path: %v\n", patPath)
				return
			}
			matchOk = glob.Match(key)
		}
		//matchOk = true

		if matchOk {
			for ip, tag := range ips {
				fs.notify(key, value, tag, verb, ip, patPath)
			}
		}
	}
}
コード例 #2
0
ファイル: fs.go プロジェクト: izouxv/raftX
func (dir *Dir) setDirOrFile(paths []string, opType OpType, pat map[string]interface{}) (interface{}, Err, ActType) {
	pathLen := len(paths)
	if pathLen == 0 {
		//set root value
		return dir, Err_OK, kTypeExist
	}

	path := paths[0]
	lastPathItem := pathLen == 1

	if opType == OpPatGet || opType == OpPatDel {

		glob, err := CompileGlob("/" + path)
		if err != nil {
			fmt.Printf("getFile error: path: %v\n", paths)
			return nil, Err_BAD_PATH_PAT, kTypeIdle
		}

		for key, valueFd := range dir.Files {
			matchOk := false
			sameName := false
			if path == key {
				sameName = true
			} else {
				matchOk = glob.Match("/" + key)
			}
			if matchOk {
				if lastPathItem && strings.HasSuffix(path, "**") {
					//d.getOrDel(nil, files, allPath, true, pat, get)
					dir.getAllDirOrFile(valueFd, pat)
				} else {
					dir.getDirOrGetFile(valueFd, lastPathItem, paths, opType, pat)
				}
			} else if sameName {
				dir.getDirOrGetFile(valueFd, lastPathItem, paths, opType, pat)
			}
		}
		if len(pat) > 0 {
			return nil, Err_OK, kTypeExist
		}
	} else {
		//fmt.Printf("set: %v->%v:%v\n", allPath, path, value)
		fd, found := dir.Files[path]
		if found {
			return dir.getDirOrGetFile(fd, lastPathItem, paths, opType, pat)
		}

		if opType == OpGet || opType == OpDel {
			return nil, Err_NOT_EXIST, kTypeIdle //ErrDirNotExist
		}

		if opType == OpMkDirAll || opType == OpMkAutoMkDirAndLastFile {

			newPwd := dir.Abs + path + "/"

			createDirOrFile := false
			if lastPathItem { //到文件尾部
				createDirOrFile = true
			} else {
				//fmt.Printf("createDir2: %v:%v\n", allPath, newPwd)
				//fmt.Printf("mkdir: %v\n, %v\n", newPwd, paths)
				newItem := NewDir(newPwd, "")
				dir.Files[path] = newItem
				newItem.setDir(dir)
				//fmt.Printf("mkDir   %v  %v\n", allPath, newPwd)
				return dir.setDirOrFile(paths, opType, pat)
			}

			if createDirOrFile {
				if opType == OpMkDirAll {
					//	fmt.Printf("mkDir   %v  %v\n", allPath, paths)
					fileOrDir := NewDir(newPwd, "")
					dir.Files[path] = fileOrDir
					fileOrDir.setDir(dir)
					return fileOrDir, Err_OK, kTypeCreate
				} else if opType == OpMkAutoMkDirAndLastFile {
					//	fmt.Printf("mkFile   %v  %v\n", allPath, paths)
					fileOrDir := NewFile(path, "")
					dir.Files[path] = fileOrDir
					fileOrDir.setDir(dir)
					return fileOrDir, Err_OK, kTypeCreate
				}
			}
		}
	}
	return nil, Err_UNKNOWN, kTypeIdle
}