Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
anjor committed Jul 8, 2024
1 parent 320cec4 commit 042adca
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions cmd-car-split.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,30 @@ func newCmd_SplitCar() *cli.Command {
}))
})
if err != nil {
return err
return fmt.Errorf("failed to construct a subsetNode: %s", err)
}

cid, err := writeNode(subsetNode, currentFile)
if err != nil {
return err
return fmt.Errorf("failed to write a subsetNode: %s", err)
}

subsetLinks = append(subsetLinks, cidlink.Link{Cid: cid})

currentFile.Close()
if err = currentFile.Close(); err != nil {
return fmt.Errorf("failed to close file: %s", err)
}
}
currentFileNum++
filename := fmt.Sprintf("epoch-%d-%d.car", epoch, currentFileNum)
currentFile, err = os.Create(filename)
if err != nil {
return err
return fmt.Errorf("failed to create file %s: %s", filename, err)
}
// Write the header
_, err = io.WriteString(currentFile, nulRootCarHeader)
if err != nil {
return err
return fmt.Errorf("failed to write header: %s", err)
}

// Set the currentFileSize to the size of the header
Expand All @@ -172,7 +174,7 @@ func newCmd_SplitCar() *cli.Command {

if needNewFile {
if err := createNewFile(); err != nil {
return err
return fmt.Errorf("failed to create a new file: %s", err)
}
}

Expand All @@ -191,13 +193,13 @@ func newCmd_SplitCar() *cli.Command {
data := owm.ObjectData
kind, err := iplddecoders.GetKind(data)
if err != nil {
return err
return fmt.Errorf("failed to get kind: %s", err)
}

if kind == iplddecoders.KindBlock {
block, err := iplddecoders.DecodeBlock(data)
if err != nil {
return err
return fmt.Errorf("failed to decode block: %s", err)
}

if currentSubsetInfo.firstSlot == -1 || block.Slot < currentSubsetInfo.firstSlot {
Expand All @@ -212,7 +214,7 @@ func newCmd_SplitCar() *cli.Command {

rs, err := owm.RawSection()
if err != nil {
return err
return fmt.Errorf("failed to get raw section: %s", err)
}

return writeObject(rs)
Expand All @@ -224,12 +226,12 @@ func newCmd_SplitCar() *cli.Command {
func(owm1 *accum.ObjectWithMetadata, owm2 []accum.ObjectWithMetadata) error {
for _, owm := range owm2 {
if err := processObject(&owm); err != nil {
return err
return fmt.Errorf("failed to process object: %s", err)
}
}

if err := processObject(owm1); err != nil {
return err
return fmt.Errorf("failed to process object: %s", err)
}
return nil
},
Expand All @@ -253,12 +255,12 @@ func newCmd_SplitCar() *cli.Command {
}))
})
if err != nil {
return err
return fmt.Errorf("failed to construct subsetNode: %s", err)
}

cid, err := writeNode(subsetNode, currentFile)
if err != nil {
return err
return fmt.Errorf("failed to write subsetNode: %s", err)
}

subsetLinks = append(subsetLinks, cidlink.Link{Cid: cid})
Expand All @@ -275,14 +277,17 @@ func newCmd_SplitCar() *cli.Command {
)
})
if err != nil {
return err
return fmt.Errorf("failed to construct epochNode: %s", err)
}

_, err = writeNode(epochNode, currentFile)
if err != nil {
return err
return fmt.Errorf("failed to write epochNode: %s", err)
}
err = currentFile.Close()
if err != nil {
return fmt.Errorf("failed to close file: %s", err)
}
currentFile.Close()

return nil
},
Expand Down

0 comments on commit 042adca

Please sign in to comment.