Skip to content

Commit

Permalink
fix list file (#1288)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hitenjain14 authored Oct 10, 2023
1 parent e61d277 commit e2ded67
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
Original file line number Diff line number Diff line change
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 e2ded67

Please sign in to comment.