Skip to content

Commit dc95f36

Browse files
committed
box: fix about: cannot unmarshal number 1.0e+18 into Go struct field
Before this change rclone about was failing with cannot unmarshal number 1.0e+18 into Go struct field User.space_amount of type int64 As Box increased Enterprise accounts user.space_amount from 30PB to 1e+18 or 888.178PB returning it as a floating point number, not an integer. This fix reads it as a float64 and clips it to the maximum value of an int64 if necessary.
1 parent d3e3af3 commit dc95f36

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

backend/box/api/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ type User struct {
271271
ModifiedAt time.Time `json:"modified_at"`
272272
Language string `json:"language"`
273273
Timezone string `json:"timezone"`
274-
SpaceAmount int64 `json:"space_amount"`
275-
SpaceUsed int64 `json:"space_used"`
276-
MaxUploadSize int64 `json:"max_upload_size"`
274+
SpaceAmount float64 `json:"space_amount"`
275+
SpaceUsed float64 `json:"space_used"`
276+
MaxUploadSize float64 `json:"max_upload_size"`
277277
Status string `json:"status"`
278278
JobTitle string `json:"job_title"`
279279
Phone string `json:"phone"`

fs/types.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"encoding/json"
99
"io"
10+
"math"
1011
"time"
1112

1213
"github.com/rclone/rclone/fs/hash"
@@ -335,9 +336,15 @@ type FlaggerNP interface {
335336
}
336337

337338
// NewUsageValue makes a valid value
338-
func NewUsageValue(value int64) *int64 {
339+
func NewUsageValue[T interface {
340+
int64 | uint64 | float64
341+
}](value T) *int64 {
339342
p := new(int64)
340-
*p = value
343+
if value > T(int64(math.MaxInt64)) {
344+
*p = math.MaxInt64
345+
} else {
346+
*p = int64(value)
347+
}
341348
return p
342349
}
343350

0 commit comments

Comments
 (0)