Skip to content

Commit

Permalink
write at end
Browse files Browse the repository at this point in the history
  • Loading branch information
anjor committed Jul 30, 2024
1 parent b77c76b commit 20a3bf6
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions cmd-car-split.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type carFile struct {

type Metadata struct {
FileName string `yaml:"filename"`
FileSize int64 `yaml:"fileSize"`
FirstSlot int `yaml:"firstSlot"`
LastSlot int `yaml:"lastSlot"`
Cid string `yaml:"cid"`
Expand Down Expand Up @@ -158,6 +159,7 @@ func newCmd_SplitCar() *cli.Command {
subsetLinks []datamodel.Link
writer io.Writer
carFiles []carFile
metadata []Metadata
)

createNewFile := func() error {
Expand All @@ -181,18 +183,7 @@ func newCmd_SplitCar() *cli.Command {

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

// write metadata
m := Metadata{
FileName: currentSubsetInfo.fileName,
FirstSlot: currentSubsetInfo.firstSlot,
LastSlot: currentSubsetInfo.lastSlot,
Cid: sl.String(),
}

err = writeMetadata(m, epoch)
if err != nil {
return fmt.Errorf("failed to write metadata: %w", err)
}
metadata = append(metadata, Metadata{FileName: currentSubsetInfo.fileName, FileSize: currentFileSize, FirstSlot: currentSubsetInfo.firstSlot, LastSlot: currentSubsetInfo.lastSlot, Cid: sl.String()})

err = closeFile(bufferedWriter, currentFile)
if err != nil {
Expand Down Expand Up @@ -307,18 +298,7 @@ func newCmd_SplitCar() *cli.Command {
}
subsetLinks = append(subsetLinks, sl)

// write metadata
m := Metadata{
FileName: currentSubsetInfo.fileName,
FirstSlot: currentSubsetInfo.firstSlot,
LastSlot: currentSubsetInfo.lastSlot,
Cid: sl.String(),
}

err = writeMetadata(m, epoch)
if err != nil {
return fmt.Errorf("failed to write metadata: %w", err)
}
metadata = append(metadata, Metadata{FileName: currentSubsetInfo.fileName, FileSize: currentFileSize, FirstSlot: currentSubsetInfo.firstSlot, LastSlot: currentSubsetInfo.lastSlot, Cid: sl.String()})

epochNode, err := qp.BuildMap(ipldbindcode.Prototypes.Epoch, -1, func(ma datamodel.MapAssembler) {
qp.MapEntry(ma, "kind", qp.Int(int64(iplddecoders.KindEpoch)))
Expand Down Expand Up @@ -372,6 +352,16 @@ func newCmd_SplitCar() *cli.Command {
strconv.FormatUint(c.paddedSize, 10),
strconv.FormatInt(c.fileSize, 10),
})
if err != nil {
return fmt.Errorf("failed to write metatadata csv: %w", err)
}
}

for _, m := range metadata {
err = writeMetadata(m, epoch)
if err != nil {
return fmt.Errorf("failed to write metatadata yaml: %w", err)
}
}

return closeFile(bufferedWriter, currentFile)
Expand Down

0 comments on commit 20a3bf6

Please sign in to comment.