diff --git a/pkg/gateway/gateway.go b/pkg/gateway/gateway.go index dd10c89bacd5..fc9b46582c90 100644 --- a/pkg/gateway/gateway.go +++ b/pkg/gateway/gateway.go @@ -333,6 +333,14 @@ func (n *jfsObjects) listDirFactory() minio.ListDirFunc { if root && (fi.Name() == metaBucket || fi.Name() == minio.MinioMetaBucket) { continue } + if stat, ok := fi.(*fs.FileStat); ok && stat.IsSymlink() { + var err syscall.Errno + p := n.path(bucket, prefixDir, fi.Name()) + if fi, err = n.fs.Stat(mctx, p); err != 0 { + logger.Errorf("stat %s: %s", p, err) + continue + } + } entry := &minio.Entry{Name: fi.Name(), Info: &minio.ObjectInfo{ Bucket: bucket, @@ -343,14 +351,7 @@ func (n *jfsObjects) listDirFactory() minio.ListDirFunc { AccTime: fi.ModTime(), }, } - if stat, ok := fi.(*fs.FileStat); ok && stat.IsSymlink() { - var err syscall.Errno - p := n.path(bucket, prefixDir, fi.Name()) - if fi, err = n.fs.Stat(mctx, p); err != 0 { - logger.Errorf("stat %s: %s", p, err) - continue - } - } + if fi.IsDir() { entry.Name += sep entry.Info.Size = 0 @@ -381,37 +382,38 @@ func (n *jfsObjects) ListObjects(ctx context.Context, bucket, prefix, marker, de return loi, err } getObjectInfo := func(ctx context.Context, bucket, object string, info *minio.ObjectInfo) (obj minio.ObjectInfo, err error) { - if info != nil && info.Size > 0 { - info.Name = object - return *info, nil - } - fi, eno := n.fs.Stat(mctx, n.path(bucket, object)) - if eno == 0 { - size := fi.Size() - if fi.IsDir() { - size = 0 - } - info = &minio.ObjectInfo{ - Bucket: bucket, - ModTime: fi.ModTime(), - Size: size, - IsDir: fi.IsDir(), - AccTime: fi.ModTime(), + var eno syscall.Errno + if info == nil { + var fi *fs.FileStat + fi, eno = n.fs.Stat(mctx, n.path(bucket, object)) + if eno == 0 { + size := fi.Size() + if fi.IsDir() { + size = 0 + } + info = &minio.ObjectInfo{ + Bucket: bucket, + ModTime: fi.ModTime(), + Size: size, + IsDir: fi.IsDir(), + AccTime: fi.ModTime(), + } } - } - // replace links to external file systems with empty files - if eno == syscall.ENOTSUP { - now := time.Now() - info = &minio.ObjectInfo{ - Bucket: bucket, - ModTime: now, - Size: 0, - IsDir: false, - AccTime: now, + // replace links to external file systems with empty files + if errors.Is(eno, syscall.ENOTSUP) { + now := time.Now() + info = &minio.ObjectInfo{ + Bucket: bucket, + ModTime: now, + Size: 0, + IsDir: false, + AccTime: now, + } + eno = 0 } - eno = 0 } + if info == nil { return obj, jfsToObjectErr(ctx, eno, bucket, object) }