fix token refresh routine not exit error

This commit is contained in:
xiaoyaofenfen 2022-12-21 16:27:39 +08:00
parent b74d39da41
commit ed38002e65
4 changed files with 38 additions and 12 deletions

View File

@ -33,6 +33,7 @@ import (
"path"
"path/filepath"
"runtime"
"sync/atomic"
"time"
)
@ -226,14 +227,19 @@ func RunDownload(paths []string, options *DownloadOptions) {
activeUser.PanClient().ClearCache()
defer activeUser.PanClient().DisableCache()
// pan token expired checker
go func() {
for {
continueFlag := int32(0)
atomic.StoreInt32(&continueFlag, 0)
defer func() {
atomic.StoreInt32(&continueFlag, 1)
}()
go func(flag *int32) {
for atomic.LoadInt32(flag) == 0 {
time.Sleep(time.Duration(1) * time.Minute)
if RefreshTokenInNeed(activeUser) {
logger.Verboseln("update access token for download task")
}
}
}()
}(&continueFlag)
if options == nil {
options = &DownloadOptions{}

View File

@ -28,6 +28,7 @@ import (
"os"
"path"
"strings"
"sync/atomic"
"time"
)
@ -305,15 +306,20 @@ func RunSync(defaultTask *syncdrive.SyncTask, fileDownloadParallel, fileUploadPa
panClient.DisableCache()
// pan token expired checker
go func() {
for {
continueFlag := int32(0)
atomic.StoreInt32(&continueFlag, 0)
defer func() {
atomic.StoreInt32(&continueFlag, 1)
}()
go func(flag *int32) {
for atomic.LoadInt32(flag) == 0 {
time.Sleep(time.Duration(1) * time.Minute)
if RefreshTokenInNeed(activeUser) {
logger.Verboseln("update access token for sync task")
panClient.UpdateToken(activeUser.WebToken)
}
}
}()
}(&continueFlag)
syncFolderRootPath := config.GetSyncDriveDir()
if b, e := utils.PathExists(syncFolderRootPath); e == nil {

View File

@ -27,6 +27,7 @@ import (
"path/filepath"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/tickstep/library-go/logger"
@ -268,14 +269,19 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
activeUser.PanClient().ClearCache()
defer activeUser.PanClient().DisableCache()
// pan token expired checker
go func() {
for {
continueFlag := int32(0)
atomic.StoreInt32(&continueFlag, 0)
defer func() {
atomic.StoreInt32(&continueFlag, 1)
}()
go func(flag *int32) {
for atomic.LoadInt32(flag) == 0 {
time.Sleep(time.Duration(1) * time.Minute)
if RefreshTokenInNeed(activeUser) {
logger.Verboseln("update access token for upload task")
}
}
}()
}(&continueFlag)
if opt == nil {
opt = &UploadOptions{}

View File

@ -21,6 +21,7 @@ import (
"github.com/tickstep/library-go/logger"
"github.com/urfave/cli"
"strings"
"sync/atomic"
"time"
)
@ -72,8 +73,15 @@ aliyunpan webdav start -h
return nil
}
activeUser := GetActiveUser()
go func() {
for {
// pan token expired checker
continueFlag := int32(0)
atomic.StoreInt32(&continueFlag, 0)
defer func() {
atomic.StoreInt32(&continueFlag, 1)
}()
go func(flag *int32) {
for atomic.LoadInt32(flag) == 0 {
// token刷新
time.Sleep(time.Duration(1) * time.Minute)
//time.Sleep(time.Duration(5) * time.Second)
@ -81,7 +89,7 @@ aliyunpan webdav start -h
logger.Verboseln("reload new access token for webdav")
}
}
}()
}(&continueFlag)
webdavServ := &webdav.WebdavConfig{
PanDriveId: "",