Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
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
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