From 3bf2873102fe52f56bf2e495313e165955857f3a Mon Sep 17 00:00:00 2001 From: anjor Date: Tue, 17 Sep 2024 14:20:15 +0100 Subject: [PATCH] m --- cmd-car-split.go | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/cmd-car-split.go b/cmd-car-split.go index 0530a58d..592df648 100644 --- a/cmd-car-split.go +++ b/cmd-car-split.go @@ -175,9 +175,25 @@ 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}) - - metadata.CarPieces.CarPieces = append(metadata.CarPieces.CarPieces, carlet.CarFile{Name: currentSubsetInfo.fileName, ContentSize: currentFileSize, HeaderSize: uint64(len(nulRootCarHeader)), CommP: commCid}) + carFiles = append( + carFiles, + carFile{ + name: fmt.Sprintf("epoch-%d-%d.car", epoch, currentFileNum), + commP: commCid, + payloadCid: sl.(cidlink.Link).Cid, + paddedSize: ps, + fileSize: currentFileSize, + }) + + metadata.CarPieces.CarPieces = append( + metadata.CarPieces.CarPieces, + carlet.CarFile{ + Name: currentSubsetInfo.fileName, + ContentSize: currentFileSize - uint64(len(nulRootCarHeader)), + HeaderSize: uint64(len(nulRootCarHeader)), + CommP: commCid, + PaddedSize: ps, + }) err = closeFile(bufferedWriter, currentFile) if err != nil { @@ -322,8 +338,23 @@ 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}) - metadata.CarPieces.CarPieces = append(metadata.CarPieces.CarPieces, carlet.CarFile{Name: currentSubsetInfo.fileName, ContentSize: currentFileSize, HeaderSize: uint64(len(nulRootCarHeader)), CommP: commCid}) + carFiles = append( + carFiles, + carFile{ + name: fmt.Sprintf("epoch-%d-%d.car", epoch, currentFileNum), + commP: commCid, + payloadCid: sl.(cidlink.Link).Cid, + paddedSize: ps, + fileSize: currentFileSize, + }) + metadata.CarPieces.CarPieces = append( + metadata.CarPieces.CarPieces, + carlet.CarFile{ + Name: currentSubsetInfo.fileName, + ContentSize: currentFileSize - uint64(len(nulRootCarHeader)), + HeaderSize: uint64(len(nulRootCarHeader)), + CommP: commCid, + }) f, err := os.Create(meta) defer f.Close() @@ -428,7 +459,7 @@ func writeNode(node datamodel.Node, w io.Writer) (cid.Cid, error) { return cd, nil } -func writeMetadata(metadata []Metadata, epoch int) error { +func writeMetadata(metadata *splitcarfetcher.Metadata, epoch int) error { metadataFileName := fmt.Sprintf("epoch-%d-metadata.yaml", epoch) // Open file in append mode