Browse Source

增加读取后缀和判断目录

master
xyiege 5 months ago
parent
commit
a166e52f7b
  1. 25
      scagent/core/JsonRpc.go

25
scagent/core/JsonRpc.go

@ -30,6 +30,9 @@ type FloopJson struct {
Path string `json:"path"`
Size string `json:"size"`
Hash string `json:"hash"`
// 文件后缀
Suffix string `json:"suffix"`
IsDir bool `json:"isdir"` // 是否是目录
}
// 文件列表
@ -52,6 +55,8 @@ func (f *FileRpcService) GetFilePath(args *Args, replay *string) error {
// 扫描指定目录下的文件,可以全部,也可以局部
func scanFileUnderPath(rootDir string, scope string, logger *zap.Logger, replay *string) {
var flplist FlpList // 文件列表
var suffix string // 文件类型
var isdir bool // 是否是目录
// 遍历所有的文件,时间长
if scope == "all" {
@ -125,19 +130,26 @@ func scanFileUnderPath(rootDir string, scope string, logger *zap.Logger, replay
if file.IsDir() {
fsize = "-"
hash = "-"
isdir = true
} else {
fsize = fmt.Sprintf("%d", fileinfo.Size())
hash = util.CalacHash(realpath)
isdir = false
// 文件的后缀
suffix = getFileSuffix(file.Name())
}
// 加入到列表
flplist.Flist = append(flplist.Flist, FloopJson{Path: file.Name(), Size: fsize, Hash: hash})
flplist.Flist = append(flplist.Flist, FloopJson{Path: file.Name(), Size: fsize, Hash: hash, Suffix: suffix, IsDir: isdir})
// allFiles = append(allFiles, filepath.Join(rootDir, file.Name()))
}
} else {
// 文件的后缀
suffix = getFileSuffix(finfo.Name())
ssize := fmt.Sprintf("%.2f KB", float64(finfo.Size())/1024)
flplist.Flist = append(flplist.Flist, FloopJson{Path: rootDir, Size: ssize, Hash: util.CalacHash(rootDir)})
flplist.Flist = append(flplist.Flist, FloopJson{Path: rootDir, Size: ssize, Hash: util.CalacHash(rootDir), Suffix: suffix, IsDir: false})
}
}
@ -153,3 +165,12 @@ func scanFileUnderPath(rootDir string, scope string, logger *zap.Logger, replay
*replay = string(jsonStr)
}
// 获取文件的后缀
func getFileSuffix(filename string) string {
// 获取文件的后缀
suffix := filepath.Ext(filename)
// 去掉.
suffix = suffix[1:]
return suffix
}

Loading…
Cancel
Save