mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 08:58:26 +08:00
filefabric: use atomic types
This commit is contained in:
parent
b6e7148daf
commit
4341d472aa
|
@ -158,7 +158,7 @@ type Fs struct {
|
||||||
tokenMu sync.Mutex // hold when reading the token
|
tokenMu sync.Mutex // hold when reading the token
|
||||||
token string // current access token
|
token string // current access token
|
||||||
tokenExpiry time.Time // time the current token expires
|
tokenExpiry time.Time // time the current token expires
|
||||||
tokenExpired int32 // read and written with atomic
|
tokenExpired atomic.Int32
|
||||||
canCopyWithName bool // set if detected that can use fi_name in copy
|
canCopyWithName bool // set if detected that can use fi_name in copy
|
||||||
precision time.Duration // precision reported
|
precision time.Duration // precision reported
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ func (f *Fs) shouldRetry(ctx context.Context, resp *http.Response, err error, st
|
||||||
err = status // return the error from the RPC
|
err = status // return the error from the RPC
|
||||||
code := status.GetCode()
|
code := status.GetCode()
|
||||||
if code == "login_token_expired" {
|
if code == "login_token_expired" {
|
||||||
atomic.AddInt32(&f.tokenExpired, 1)
|
f.tokenExpired.Add(1)
|
||||||
} else {
|
} else {
|
||||||
for _, retryCode := range retryStatusCodes {
|
for _, retryCode := range retryStatusCodes {
|
||||||
if code == retryCode.code {
|
if code == retryCode.code {
|
||||||
|
@ -323,12 +323,12 @@ func (f *Fs) getToken(ctx context.Context) (token string, err error) {
|
||||||
var refreshed = false
|
var refreshed = false
|
||||||
defer func() {
|
defer func() {
|
||||||
if refreshed {
|
if refreshed {
|
||||||
atomic.StoreInt32(&f.tokenExpired, 0)
|
f.tokenExpired.Store(0)
|
||||||
}
|
}
|
||||||
f.tokenMu.Unlock()
|
f.tokenMu.Unlock()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
expired := atomic.LoadInt32(&f.tokenExpired) != 0
|
expired := f.tokenExpired.Load() != 0
|
||||||
if expired {
|
if expired {
|
||||||
fs.Debugf(f, "Token invalid - refreshing")
|
fs.Debugf(f, "Token invalid - refreshing")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user