Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,25 @@ func (cc *commPCallback) OnSuccess(buf *Buffer, graphName, payloadCid, fsDetail
log.Infof("piece cid: %s, payload size: %d, size: %d ", cpRes.Root.String(), cpRes.PayloadSize, cpRes.Size)

buf.SeekStart()
carFileName := filepath.Join(cc.carDir, cpRes.Root.String())
if !cc.rename {
carFileName += ".car"
}
carFile, err := os.OpenFile(carFileName, os.O_RDWR|os.O_CREATE, 0o644)
carFilePath := filepath.Join(cc.carDir, cpRes.Root.String())
carFileNameWithSuffix := carFilePath + ".car"

carFile, err := os.OpenFile(carFileNameWithSuffix, os.O_RDWR|os.O_CREATE, 0o644)
if err != nil {
log.Fatalf("failed to create car file: %s", err)
}
defer carFile.Close()

if _, err = io.Copy(carFile, buf); err != nil {
log.Fatalf("failed to write car file: %s", err)
}
buf.Reset()
carFile.Close()

if cc.rename {
if err := os.Rename(carFileNameWithSuffix, carFilePath); err != nil {
log.Fatalf("failed to rename car file: %s", err)
}
}

// Add node inof to manifest.csv
manifestPath := path.Join(cc.carDir, "manifest.csv")
Expand Down