| @@ -470,47 +470,43 @@ func GetObsListObject(jobName, outPutPath, parentDir, versionName string) ([]Fil | |||||
| input := &obs.ListObjectsInput{} | input := &obs.ListObjectsInput{} | ||||
| input.Bucket = setting.Bucket | input.Bucket = setting.Bucket | ||||
| input.Prefix = strings.TrimPrefix(path.Join(setting.TrainJobModelPath, jobName, outPutPath, versionName, parentDir), "/") | 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) | output, err := ObsCli.ListObjects(input) | ||||
| fileInfos := make([]FileInfo, 0) | fileInfos := make([]FileInfo, 0) | ||||
| prefixLen := len(input.Prefix) | |||||
| fileMap := make(map[string]bool, 0) | |||||
| if err == nil { | if err == nil { | ||||
| for _, val := range output.Contents { | for _, val := range output.Contents { | ||||
| str1 := strings.Split(val.Key, "/") | |||||
| log.Info("val key=" + val.Key) | |||||
| var isDir bool | 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 | isDir = true | ||||
| if parentDir == "" { | |||||
| nextParentDir = fileName | |||||
| } else { | |||||
| nextParentDir = parentDir + "/" + fileName | |||||
| } | |||||
| if fileName == strPrefix[len(strPrefix)-1] || (fileName+"/") == outPutPath { | |||||
| continue | |||||
| } | |||||
| ParenDir += fileName + "/" | |||||
| } else { | } else { | ||||
| //files in next level dir | |||||
| if len(str1)-len(strPrefix) > 1 { | |||||
| continue | |||||
| } | |||||
| fileName = str1[len(str1)-1] | |||||
| isDir = false | isDir = false | ||||
| nextParentDir = parentDir | |||||
| } | } | ||||
| fileInfo := FileInfo{ | fileInfo := FileInfo{ | ||||
| ModTime: val.LastModified.Local().Format("2006-01-02 15:04:05"), | ModTime: val.LastModified.Local().Format("2006-01-02 15:04:05"), | ||||
| FileName: fileName, | FileName: fileName, | ||||
| Size: val.Size, | Size: val.Size, | ||||
| IsDir: isDir, | IsDir: isDir, | ||||
| ParenDir: nextParentDir, | |||||
| ParenDir: ParenDir, | |||||
| } | } | ||||
| fileInfos = append(fileInfos, fileInfo) | fileInfos = append(fileInfos, fileInfo) | ||||
| } | } | ||||