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

Commit

Permalink
utils: fall back to cumulative size evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
postables committed Apr 18, 2020
1 parent b54d5d5 commit 5b5b408
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package utils

import (
"errors"
"math/big"

"github.com/RTradeLtd/database/v2/models"
Expand All @@ -17,8 +16,15 @@ func CalculatePinCost(username, contentHash string, holdTimeInMonths int64, im r
if err != nil {
return 0, err
}
// if this is true, fall back to default calculation
// as it wont always be possible to calculate deduplicated
// storage costs if the object is not of a unixfs type
if sizeInBytes <= 0 {
return 0, errors.New("failed to calculate object size")
stats, err := im.Stat(contentHash)
if err != nil {
return 0, err
}
sizeInBytes = int64(stats.CumulativeSize)
}
// get gigabytes convert to bytes
gigaInBytes := datasize.GB.Bytes()
Expand Down

0 comments on commit 5b5b408

Please sign in to comment.