Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #616 from Starnop/md5-file-format
Browse files Browse the repository at this point in the history
feature: store piece md5s with native bytes
  • Loading branch information
lowzj authored Jun 18, 2019
2 parents 1070562 + 8d4e48f commit bc5cc1d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions supernode/daemon/mgr/cdn/file_meta_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cdn
import (
"context"
"encoding/json"
"strings"

"github.com/dragonflyoss/Dragonfly/apis/types"
cutil "github.com/dragonflyoss/Dragonfly/common/util"
Expand Down Expand Up @@ -168,12 +169,9 @@ func (mm *fileMetaDataManager) writePieceMD5s(ctx context.Context, taskID, fileM
// append the the SHA-1 checksum of pieceMD5s
pieceMD5s = append(pieceMD5s, cutil.Sha1(pieceMD5s))

data, err := json.Marshal(pieceMD5s)
if err != nil {
return err
}
pieceMD5Str := strings.Join(pieceMD5s, "\n")

return mm.fileStore.PutBytes(ctx, getMd5DataRawFunc(taskID), data)
return mm.fileStore.PutBytes(ctx, getMd5DataRawFunc(taskID), []byte(pieceMD5Str))
}

// readPieceMD5s read the md5 file of the taskID and returns the pieceMD5s.
Expand All @@ -185,9 +183,7 @@ func (mm *fileMetaDataManager) readPieceMD5s(ctx context.Context, taskID, fileMD
if err != nil {
return nil, err
}
if err := json.Unmarshal(bytes, &pieceMD5s); err != nil {
return nil, err
}
pieceMD5s = strings.Split(string(bytes), "\n")

if cutil.IsEmptySlice(pieceMD5s) {
return nil, nil
Expand Down
2 changes: 1 addition & 1 deletion supernode/daemon/mgr/cdn/file_meta_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (s *CDNFileMetaDataTestSuite) TestWriteReadFileMetaData(c *check.C) {

func (s *CDNFileMetaDataTestSuite) TestWriteReadPieceMD5s(c *check.C) {
ctx := context.TODO()
pieceMD5s := []string{"91fe186ee566659663232dcd18749cce:1502"}
pieceMD5s := []string{"91fe186ee566659663232dcd18749cce:1502", "11fe186ee566659663232dcd18749cce:1502"}
fileMD5 := "7a19c32d2c75345debe9031cfa9b649a"

err := s.metaDataManager.writePieceMD5s(ctx, taskID, fileMD5, pieceMD5s)
Expand Down

0 comments on commit bc5cc1d

Please sign in to comment.