Skip to content

Commit

Permalink
Split lobjs into header & data for deduping w/ other IPFS objects, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sameer committed Jan 4, 2019
1 parent 61547fd commit 94561ce
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions cmd/git-remote-ipld/ipld.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,41 @@ func (h *IpnsHandler) Push(remote *core.Remote, local string, remoteRef string)
func (h *IpnsHandler) bigNodePatcher(tracker *core.Tracker) func(cid.Cid, []byte) error {
return func(hash cid.Cid, data []byte) error {
if len(data) > (1 << 21) {
c, err := h.api.Add(bytes.NewReader(data))
endOfHeader := -1
for i := 0; i < len(data); i++ {
if data[i] == 0 {
endOfHeader = i + 1
break
}
}

var objectHash string
var err error
if endOfHeader > 0 {
headerHash, err := h.api.Add(bytes.NewReader(data[0:endOfHeader]))
if err != nil {
return err
}

dataHash, err := h.api.Add(bytes.NewReader(data[endOfHeader:]))
if err != nil {
return err
}

objectHash, err = h.api.PatchLink(headerHash, "0", dataHash, false)
} else {
objectHash, err = h.api.Add(bytes.NewReader(data))
}

if err != nil {
return err
}

if err := tracker.Set(LOBJ_TRACKER_PRIFIX+"/"+hash.String(), []byte(c)); err != nil {
if err := tracker.Set(LOBJ_TRACKER_PRIFIX+"/"+hash.String(), []byte(objectHash)); err != nil {
return err
}

h.currentHash, err = h.api.PatchLink(h.currentHash, "objects/"+hash.String(), c, true)
h.currentHash, err = h.api.PatchLink(h.currentHash, "objects/"+hash.String(), objectHash, true)
if err != nil {
return err
}
Expand Down

0 comments on commit 94561ce

Please sign in to comment.