From 45cdb23c12d5aa18f68b2ffeb7e0ec36436157a1 Mon Sep 17 00:00:00 2001 From: li1213987842 <30381726+li1213987842@users.noreply.github.com> Date: Tue, 12 Mar 2024 10:42:03 +0800 Subject: [PATCH] gateway: fix gateway head dir return 200 but expect 404 (#4486) --- pkg/gateway/gateway.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/gateway/gateway.go b/pkg/gateway/gateway.go index 1f89f621eeb7..647764a13d68 100644 --- a/pkg/gateway/gateway.go +++ b/pkg/gateway/gateway.go @@ -623,8 +623,15 @@ func (n *jfsObjects) GetObjectInfo(ctx context.Context, bucket, object string, o err = jfsToObjectErr(ctx, eno, bucket, object) return } - // put /dir1/key1; head /dir1 return 404; head /dir1/ return 200 - if strings.HasSuffix(object, sep) && !fi.IsDir() || !strings.HasSuffix(object, sep) && fi.IsDir() { + // put /dir1/key1; head /dir1 return 404; head /dir1/ return 404; head /dir1/key1 return 200 + // put /dir1/key1/; head /dir1/key1 return 404; head /dir1/key1/ return 200 + var isObject bool + if strings.HasSuffix(object, sep) && fi.IsDir() && fi.Atime() == 0 { + isObject = true + } else if !strings.HasSuffix(object, sep) && !fi.IsDir() { + isObject = true + } + if !isObject { err = jfsToObjectErr(ctx, syscall.ENOENT, bucket, object) return }