Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
utils: enable deduplicate size calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
postables committed Apr 18, 2020
1 parent c20bf72 commit e6955ac
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utils

import (
"errors"
"math/big"

"github.com/RTradeLtd/database/v2/models"
Expand All @@ -10,12 +11,15 @@ import (

// CalculatePinCost is used to calculate the cost of pining a particular content hash
func CalculatePinCost(username, contentHash string, holdTimeInMonths int64, im rtfs.Manager, um *models.UsageManager) (float64, error) {
objectStat, err := im.Stat(contentHash)
// get total size of content hash in bytes ensuring that we calculate size
// by following unique references
sizeInBytes, _, err := rtfs.DedupAndCalculatePinSize(contentHash, im)
if err != nil {
return float64(0), err
return 0, err
}
if sizeInBytes <= 0 {
return 0, errors.New("failed to calculate object size")
}
// get total size of content hash in bytes
sizeInBytes := objectStat.CumulativeSize
// get gigabytes convert to bytes
gigaInBytes := datasize.GB.Bytes()
// convert size of content hash form int to float64
Expand Down

0 comments on commit e6955ac

Please sign in to comment.