File tree Expand file tree Collapse file tree 1 file changed +28
-4
lines changed
Expand file tree Collapse file tree 1 file changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -455,11 +455,35 @@ func (dag *Dag) GetContentFromLeaf(leaf *DagLeaf) ([]byte, error) {
455455 var content []byte
456456
457457 if len (leaf .Links ) > 0 {
458- // For chunked files, concatenate content from all chunks
459- for _ , link := range leaf .Links {
460- childLeaf := dag .Leafs [link ]
458+ // For chunked files, sort links by label and concatenate content from all chunks
459+ var sortedLinks []struct {
460+ Label int
461+ Link string
462+ }
463+
464+ for label , link := range leaf .Links {
465+ labelNum , err := strconv .Atoi (label )
466+ if err != nil {
467+ return nil , fmt .Errorf ("invalid link label: %s" , label )
468+ }
469+
470+ sortedLinks = append (sortedLinks , struct {
471+ Label int
472+ Link string
473+ }{
474+ Label : labelNum ,
475+ Link : link ,
476+ })
477+ }
478+
479+ sort .Slice (sortedLinks , func (i , j int ) bool {
480+ return sortedLinks [i ].Label < sortedLinks [j ].Label
481+ })
482+
483+ for _ , item := range sortedLinks {
484+ childLeaf := dag .Leafs [item .Link ]
461485 if childLeaf == nil {
462- return nil , fmt .Errorf ("invalid link: %s" , link )
486+ return nil , fmt .Errorf ("invalid link: %s" , item . Link )
463487 }
464488
465489 content = append (content , childLeaf .Content ... )
You can’t perform that action at this time.
0 commit comments