Skip to content

Commit 8036805

Browse files
authored
Merge pull request #22 from filecoin-project/feat/sha256sum
feat: compute sha256
2 parents fdecd41 + 67e1c9f commit 8036805

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cmd/filsnap/cmds/create.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package cmds
22

33
import (
44
"context"
5+
"crypto/sha256"
56
"errors"
67
"fmt"
78
"io"
89
"io/ioutil"
10+
"strings"
911
"syscall"
1012
"time"
1113

@@ -241,6 +243,9 @@ var cmdCreate = &cli.Command{
241243
}
242244

243245
r, w := io.Pipe()
246+
h := sha256.New()
247+
248+
tr := io.TeeReader(r, h)
244249

245250
e := export.NewExport(node, tsk, abi.ChainEpoch(flagStaterootCount), true, w)
246251
errCh := make(chan error)
@@ -298,7 +303,7 @@ var cmdCreate = &cli.Command{
298303
Secure: false,
299304
})
300305

301-
info, err := minioClient.PutObject(ctx, flagBucket, fmt.Sprintf("%d.car", height), r, -1, minio.PutObjectOptions{})
306+
info, err := minioClient.PutObject(ctx, flagBucket, fmt.Sprintf("%d.car", height), tr, -1, minio.PutObjectOptions{})
302307
if err != nil {
303308
return err
304309
}
@@ -313,13 +318,18 @@ var cmdCreate = &cli.Command{
313318
"expiration", info.Expiration,
314319
"expiration_rule_id", info.ExpirationRuleID,
315320
)
321+
322+
info, err = minioClient.PutObject(ctx, flagBucket, fmt.Sprintf("%s.sha256sum", info.Key), strings.NewReader(fmt.Sprintf("%x", h.Sum(nil))), -1, minio.PutObjectOptions{})
323+
if err != nil {
324+
logger.Errorw("failed to write sha256sum", "object", info.Key, "err", err)
325+
}
316326
}
317327

318328
if err := <-errCh; err != nil {
319329
return err
320330
}
321331

322-
logger.Infow("finished")
332+
logger.Infow("finished", "digiest", fmt.Sprintf("%x", h.Sum(nil)))
323333

324334
return nil
325335
},

0 commit comments

Comments
 (0)