From c699c50c7df093fb9f856fa071ae497b6f183bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=9A=E8=BE=85=E5=85=89?= <9330@9ji.com> Date: Tue, 22 Nov 2022 09:33:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=8EOSS=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=A4=96=E9=83=A8=E6=95=B0=E6=8D=AE=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=A4=9A=E7=BA=A7=E7=9B=AE=E5=BD=95=E5=81=B6=E5=B0=94=E4=BC=9A?= =?UTF-8?q?=E8=A2=AB=E5=BD=93=E5=81=9A=E6=96=87=E4=BB=B6=E5=A4=84=E7=90=86?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/filesystem/driver/oss/handler.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/pkg/filesystem/driver/oss/handler.go b/pkg/filesystem/driver/oss/handler.go index af27816..d8fa182 100644 --- a/pkg/filesystem/driver/oss/handler.go +++ b/pkg/filesystem/driver/oss/handler.go @@ -171,14 +171,25 @@ func (handler *Driver) List(ctx context.Context, base string, recursive bool) ([ if err != nil { continue } - res = append(res, response.Object{ - Name: path.Base(object.Key), - Source: object.Key, - RelativePath: filepath.ToSlash(rel), - Size: uint64(object.Size), - IsDir: false, - LastModify: object.LastModified, - }) + // oss sdk返回的数据在多级目录的情况下偶尔有问题,有些目录被当做了文件处理 + if strings.HasSuffix(object.Key, "/") { + res = append(res, response.Object{ + Name: path.Base(object.Key), + RelativePath: filepath.ToSlash(rel), + Size: 0, + IsDir: true, + LastModify: time.Now(), + }) + } else { + res = append(res, response.Object{ + Name: path.Base(object.Key), + Source: object.Key, + RelativePath: filepath.ToSlash(rel), + Size: uint64(object.Size), + IsDir: false, + LastModify: object.LastModified, + }) + } } return res, nil