1
mirror of https://github.com/rclone/rclone synced 2024-11-10 08:08:35 +01:00

rc: fix setting bwlimit to unlimited

This commit is contained in:
Nick Craig-Wood 2018-04-24 09:43:07 +01:00
parent 764440068e
commit 9f04ce282e

View File

@ -115,6 +115,19 @@ func limitBandwidth(n int) {
tokenBucketMu.Unlock()
}
// SetBwLimit sets the current bandwidth limit
func SetBwLimit(bandwidth fs.SizeSuffix) {
tokenBucketMu.Lock()
defer tokenBucketMu.Unlock()
if bandwidth > 0 {
tokenBucket = newTokenBucket(bandwidth)
fs.Logf(nil, "Bandwidth limit set to %v", bandwidth)
} else {
tokenBucket = nil
fs.Logf(nil, "Bandwidth limit reset to unlimited")
}
}
// Remote control for the token bucket
func init() {
rc.Add(rc.Call{
@ -137,10 +150,7 @@ func init() {
return out, errors.New("need exactly 1 bandwidth setting")
}
bw := bws[0]
tokenBucketMu.Lock()
tokenBucket = newTokenBucket(bw.Bandwidth)
tokenBucketMu.Unlock()
fs.Logf(nil, "Bandwidth limit set to %v", bw.Bandwidth)
SetBwLimit(bw.Bandwidth)
return rc.Params{"rate": bw.Bandwidth.String()}, nil
},
Title: "Set the bandwidth limit.",