package models import ( "errors" "path" ) func ParsePathComponents(pathStr string) (parentPath, nodeName string, nodeType VfsNodeType, err error) { // FIXME: 路径判断以及update的类型判断 abspath := path.Clean(pathStr) if !path.IsAbs(abspath) { return "", "", 0, errors.New("path must be absolute") } // 特殊处理根路径 if abspath == "/" { return "", "", VfsNodeTypeDirectory, nil } // 判断是文件还是目录 nodeType = VfsNodeTypeFile // 如果原始路径以 / 结尾,则为目录 if len(pathStr) > 1 && pathStr[len(pathStr)-1] == '/' { nodeType = VfsNodeTypeDirectory } if nodeType == VfsNodeTypeFile && path.Ext(pathStr) == ".api" { nodeType = VfsNodeTypeService } // 分割路径 parentPath, nodeName = path.Split(abspath) // 清理父路径 if parentPath != "/" && parentPath != "" { parentPath = path.Clean(parentPath) } // 处理特殊情况 if parentPath == "." { parentPath = "/" } return parentPath, nodeName, nodeType, nil }