From 4fc6bd95720d32157f8fddcbca7c4e21e93870f2 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 6 Jan 2022 14:35:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=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 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/storage/obs.go b/modules/storage/obs.go index e20512f59..32251ef70 100755 --- a/modules/storage/obs.go +++ b/modules/storage/obs.go @@ -28,6 +28,13 @@ type FileInfo struct { ParenDir string `json:"ParenDir"` UUID string `json:"UUID"` } +type FileInfoList []FileInfo + +func (ulist FileInfoList) Swap(i, j int) { ulist[i], ulist[j] = ulist[j], ulist[i] } +func (ulist FileInfoList) Len() int { return len(ulist) } +func (ulist FileInfoList) Less(i, j int) bool { + return strings.Compare(ulist[i].ModTime, ulist[j].ModTime) > 0 +} //check if has the object func ObsHasObject(path string) (bool, error) { @@ -333,7 +340,8 @@ func GetAllObjectByBucketAndPrefix(bucket string, prefix string) ([]FileInfo, er input.MaxKeys = 100 input.Prefix = prefix index := 1 - fileInfos := make([]FileInfo, 0) + fileInfoList := FileInfoList{} + prefixLen := len(prefix) log.Info("prefix=" + input.Prefix) for { @@ -358,7 +366,7 @@ func GetAllObjectByBucketAndPrefix(bucket string, prefix string) ([]FileInfo, er IsDir: isDir, ParenDir: "", } - fileInfos = append(fileInfos, fileInfo) + fileInfoList = append(fileInfoList, fileInfo) } if output.IsTruncated { input.Marker = output.NextMarker @@ -373,7 +381,8 @@ func GetAllObjectByBucketAndPrefix(bucket string, prefix string) ([]FileInfo, er return nil, err } } - return fileInfos, nil + sort.Sort(fileInfoList) + return fileInfoList, nil } func GetObsListObject(jobName, outPutPath, parentDir, versionName string) ([]FileInfo, error) {