Skip to content

Commit

Permalink
fix: respect unixfs lexicographical sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorropo committed Aug 7, 2022
1 parent 262ac5b commit e99b191
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,16 +498,15 @@ TaskLoop:

func (r *recursiveTraverser) makeSendPayload(job sendJobs) ([]byte, int64, error) {
cidsToLink := make([]*pb.PBLink, len(job.roots))
var nameCounter uint64
for _, v := range job.roots {
padSize := len(strconv.FormatUint(uint64(len(job.roots)-1), 32))
for i, v := range job.roots {
sSize := uint64(v.DagSize)
n := strconv.FormatUint(uint64(nameCounter), 32)
cidsToLink[nameCounter] = &pb.PBLink{
n := zeroPad(strconv.FormatUint(uint64(i), 32), padSize)
cidsToLink[i] = &pb.PBLink{
Name: &n,
Tsize: &sSize,
Hash: v.Cid.Bytes(),
}
nameCounter++
}

// Write a linking root if we have multiple roots
Expand Down Expand Up @@ -579,13 +578,12 @@ func (r *recursiveTraverser) makeSendPayload(job sendJobs) ([]byte, int64, error
}
c := cid.NewCidV1(cid.DagProtobuf, mhash)
data = append(append(append(varuintHeader, c.Bytes()...), blockData...), data...)
n := strconv.FormatUint(uint64(nameCounter), 32)
n := "0"
cidsToLink[0] = &pb.PBLink{
Name: &n,
Tsize: &sSize,
Hash: c.Bytes(),
}
nameCounter++
}

// Writing CAR header
Expand Down Expand Up @@ -1317,3 +1315,10 @@ func makeFileRoot(ins []*cidSizePair) ([]byte, int64, error) {
})
return data, fileSum, err
}

func zeroPad(s string, i int) string {
for len(s) < i {
s = "0" + s
}
return s
}

0 comments on commit e99b191

Please sign in to comment.