Skip to content

Commit

Permalink
fix list file
Browse files Browse the repository at this point in the history
  • Loading branch information
Hitenjain14 committed Oct 10, 2023
1 parent e61d277 commit 6911845
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion code/go/0chain.net/blobbercore/handler/storage_handler.go
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 6911845

Please sign in to comment.