From 35ee610d4963df0a28fd67fdaba02f9df43c2a2a Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 21 Jun 2022 16:37:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=A0=91=E5=BD=A2=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=99=A8=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- modules/storage/obs.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/modules/storage/obs.go b/modules/storage/obs.go index 0ad48a51c..1e347d145 100755 --- a/modules/storage/obs.go +++ b/modules/storage/obs.go @@ -353,6 +353,7 @@ func GetOneLevelAllObjectUnderDir(bucket string, prefixRootPath string, relative 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 { log.Info("val key=" + val.Key) @@ -362,16 +363,27 @@ func GetOneLevelAllObjectUnderDir(bucket string, prefixRootPath string, relative continue } if strings.Contains(val.Key[prefixLen:len(val.Key)-1], "/") { - continue - } - if strings.HasSuffix(val.Key, "/") { - isDir = true fileName = val.Key[prefixLen : len(val.Key)-1] - relativePath += val.Key[prefixLen:] + files := strings.Split(fileName, "/") + fileName = files[0] + isDir = true + if fileMap[files[0]] { + continue + } else { + fileMap[files[0]] = true + } } else { - isDir = false - fileName = val.Key[prefixLen:] + if strings.HasSuffix(val.Key, "/") { + isDir = true + fileName = val.Key[prefixLen : len(val.Key)-1] + relativePath += val.Key[prefixLen:] + } else { + isDir = false + fileName = val.Key[prefixLen:] + } + fileMap[fileName] = true } + fileInfo := FileInfo{ ModTime: val.LastModified.Local().Format("2006-01-02 15:04:05"), FileName: fileName,