Skip to content

Commit

Permalink
set root in header
Browse files Browse the repository at this point in the history
  • Loading branch information
anjor committed Aug 15, 2024
1 parent 41089cf commit ec0c0d3
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions cmd-car-split.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
commp "github.com/filecoin-project/go-fil-commp-hashhash"
"github.com/filecoin-project/go-leb128"
"github.com/ipfs/go-cid"
"github.com/ipld/go-car/v2"
"github.com/ipld/go-ipld-prime/codec/dagcbor"
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/fluent/qp"
Expand Down Expand Up @@ -171,13 +172,19 @@ func newCmd_SplitCar() *cli.Command {
return fmt.Errorf("failed to calculate commitment to cid: %w", err)
}

carFiles = append(carFiles, carFile{name: fmt.Sprintf("epoch-%d-%d.car", epoch, currentFileNum), commP: commCid, payloadCid: sl.(cidlink.Link).Cid, paddedSize: ps, fileSize: currentFileSize})
cf := carFile{name: fmt.Sprintf("epoch-%d-%d.car", epoch, currentFileNum), commP: commCid, payloadCid: sl.(cidlink.Link).Cid, paddedSize: ps, fileSize: currentFileSize}
carFiles = append(carFiles, cf)

err = closeFile(bufferedWriter, currentFile)
if err != nil {
return fmt.Errorf("failed to close file: %w", err)
}

err = car.ReplaceRootsInFile(cf.name, []cid.Cid{cf.payloadCid})
if err != nil {
return fmt.Errorf("failed to replace root: %w", err)
}

cp.Reset()
}

Expand Down Expand Up @@ -316,7 +323,18 @@ func newCmd_SplitCar() *cli.Command {
return fmt.Errorf("failed to calculate commitment to cid: %w", err)
}

carFiles = append(carFiles, carFile{name: fmt.Sprintf("epoch-%d-%d.car", epoch, currentFileNum), commP: commCid, payloadCid: sl.(cidlink.Link).Cid, paddedSize: ps, fileSize: currentFileSize})
cf := carFile{name: fmt.Sprintf("epoch-%d-%d.car", epoch, currentFileNum), commP: commCid, payloadCid: sl.(cidlink.Link).Cid, paddedSize: ps, fileSize: currentFileSize}
carFiles = append(carFiles, cf)

err = closeFile(bufferedWriter, currentFile)
if err != nil {
return fmt.Errorf("failed to close file: %w", err)
}

err = car.ReplaceRootsInFile(cf.name, []cid.Cid{cf.payloadCid})
if err != nil {
return fmt.Errorf("failed to replace root: %w", err)
}

f, err := os.Create(meta)
defer f.Close()
Expand All @@ -340,7 +358,8 @@ func newCmd_SplitCar() *cli.Command {
})
}

return closeFile(bufferedWriter, currentFile)
return nil

},
}
}
Expand Down

0 comments on commit ec0c0d3

Please sign in to comment.