From e2ded67ae8cfcfaecb98267849c9398d95c572d6 Mon Sep 17 00:00:00 2001 From: Hitenjain14 <57557631+Hitenjain14@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:17:46 +0530 Subject: [PATCH] fix list file (#1288) --- .../go/0chain.net/blobbercore/handler/storage_handler.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/code/go/0chain.net/blobbercore/handler/storage_handler.go b/code/go/0chain.net/blobbercore/handler/storage_handler.go index 6f9d36bfc..f89b0e8b1 100644 --- a/code/go/0chain.net/blobbercore/handler/storage_handler.go +++ b/code/go/0chain.net/blobbercore/handler/storage_handler.go @@ -293,7 +293,7 @@ func (fsh *StorageHandler) ListEntities(ctx context.Context, r *http.Request) (* escapedPathHash := sanitizeString(pathHash) Logger.Info("Path Hash for list dir :" + escapedPathHash) - fileref, err := reference.GetLimitedRefFieldsByLookupHash(ctx, allocationID, pathHash, []string{"id", "path", "lookup_hash", "type", "name", "file_meta_hash"}) + fileref, err := reference.GetLimitedRefFieldsByLookupHash(ctx, allocationID, pathHash, []string{"id", "path", "lookup_hash", "type", "name", "file_meta_hash", "parent_path"}) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { // `/` always is valid even it doesn't exists in db. so ignore RecordNotFound error @@ -322,6 +322,13 @@ func (fsh *StorageHandler) ListEntities(ctx context.Context, r *http.Request) (* if fileref == nil { fileref = &reference.Ref{Type: reference.DIRECTORY, Path: path, AllocationID: allocationID} } + if fileref.Type == reference.FILE { + parent, err := reference.GetReference(ctx, allocationID, fileref.ParentPath) + if err != nil { + return nil, common.NewError("invalid_parameters", "Invalid path. Parent dir of file not found. "+err.Error()) + } + fileref = parent + } listResult.Meta = fileref.GetListingData(ctx) if clientID != allocationObj.OwnerID { delete(listResult.Meta, "path")