From 17eaafcfd07c04644d30bd9a700a9da2e93e27a3 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Mon, 31 Oct 2022 17:53:10 +0800 Subject: [PATCH] debug --- modules/storage/obs.go | 50 +++++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/modules/storage/obs.go b/modules/storage/obs.go index 2cb3af927..846020c20 100755 --- a/modules/storage/obs.go +++ b/modules/storage/obs.go @@ -470,47 +470,43 @@ func GetObsListObject(jobName, outPutPath, parentDir, versionName string) ([]Fil input := &obs.ListObjectsInput{} input.Bucket = setting.Bucket input.Prefix = strings.TrimPrefix(path.Join(setting.TrainJobModelPath, jobName, outPutPath, versionName, parentDir), "/") - log.Info("bucket=" + input.Bucket + " Prefix=" + input.Prefix) - strPrefix := strings.Split(input.Prefix, "/") + if !strings.HasSuffix(input.Prefix, "/") { + input.Prefix += "/" + } output, err := ObsCli.ListObjects(input) fileInfos := make([]FileInfo, 0) + prefixLen := len(input.Prefix) + fileMap := make(map[string]bool, 0) if err == nil { for _, val := range output.Contents { - str1 := strings.Split(val.Key, "/") + log.Info("val key=" + val.Key) var isDir bool - var fileName, nextParentDir string - if strings.HasSuffix(val.Key, "/") { - //dirs in next level dir - if len(str1)-len(strPrefix) > 2 { - continue - } - fileName = str1[len(str1)-2] + var fileName string + if val.Key == input.Prefix { + continue + } + fileName = val.Key[prefixLen:] + log.Info("fileName =" + fileName) + files := strings.Split(fileName, "/") + if fileMap[files[0]] { + continue + } else { + fileMap[files[0]] = true + } + ParenDir := parentDir + fileName = files[0] + if len(files) > 1 { isDir = true - if parentDir == "" { - nextParentDir = fileName - } else { - nextParentDir = parentDir + "/" + fileName - } - - if fileName == strPrefix[len(strPrefix)-1] || (fileName+"/") == outPutPath { - continue - } + ParenDir += fileName + "/" } else { - //files in next level dir - if len(str1)-len(strPrefix) > 1 { - continue - } - fileName = str1[len(str1)-1] isDir = false - nextParentDir = parentDir } - fileInfo := FileInfo{ ModTime: val.LastModified.Local().Format("2006-01-02 15:04:05"), FileName: fileName, Size: val.Size, IsDir: isDir, - ParenDir: nextParentDir, + ParenDir: ParenDir, } fileInfos = append(fileInfos, fileInfo) }