diff --git a/sia/uploader.go b/sia/uploader.go index 4092059..ce62ba0 100644 --- a/sia/uploader.go +++ b/sia/uploader.go @@ -93,9 +93,21 @@ func (ufs *UnixFileUploader) Add(ctx context.Context, node format.Node) error { return err } + var links []Link + for _, link := range node.Links() { + links = append(links, Link{ + CID: link.Cid, + Name: link.Name, + Size: link.Size, + }) + } + dataSize := uint64(len(data)) fileSize := ufs.fileSize + dataSize - dataOffset := ufs.dataOffset + dataSize - fileSize + dataOffset := ufs.dataOffset + if dataSize == 0 { + dataOffset = 0 + } ufs.log.Debug("adding node", zap.Stringer("cid", node.Cid()), @@ -115,15 +127,6 @@ func (ufs *UnixFileUploader) Add(ctx context.Context, node format.Node) error { return fmt.Errorf("failed to write data: %w", err) } - var links []Link - for _, link := range node.Links() { - links = append(links, Link{ - CID: link.Cid, - Name: link.Name, - Size: link.Size, - }) - } - block := Block{ CID: node.Cid(), Links: links,