fix concurrent plugin access error for sync

This commit is contained in:
xiaoyaofenfen 2022-06-20 20:37:54 +08:00
parent b64c07f079
commit 84a833db5b

View File

@ -15,6 +15,7 @@ import (
"os" "os"
"path" "path"
"strings" "strings"
"sync"
"time" "time"
) )
@ -61,7 +62,8 @@ type (
fileActionTaskManager *FileActionTaskManager fileActionTaskManager *FileActionTaskManager
plugin plugins.Plugin plugin plugins.Plugin
pluginMutex *sync.Mutex
} }
) )
@ -139,6 +141,9 @@ func (t *SyncTask) Start() error {
pluginManger := plugins.NewPluginManager(config.GetPluginDir()) pluginManger := plugins.NewPluginManager(config.GetPluginDir())
t.plugin, _ = pluginManger.GetPlugin() t.plugin, _ = pluginManger.GetPlugin()
} }
if t.pluginMutex == nil {
t.pluginMutex = &sync.Mutex{}
}
t.wg = waitgroup.NewWaitGroup(0) t.wg = waitgroup.NewWaitGroup(0)
@ -265,6 +270,8 @@ func (t *SyncTask) skipLocalFile(file *LocalFileItem) bool {
LocalFileUpdatedAt: file.UpdatedAt, LocalFileUpdatedAt: file.UpdatedAt,
DriveId: t.DriveId, DriveId: t.DriveId,
} }
t.pluginMutex.Lock()
defer t.pluginMutex.Unlock()
if result, er := t.plugin.SyncScanLocalFilePrepareCallback(plugins.GetContext(t.panUser), pluginParam); er == nil && result != nil { if result, er := t.plugin.SyncScanLocalFilePrepareCallback(plugins.GetContext(t.panUser), pluginParam); er == nil && result != nil {
if strings.Compare("no", result.SyncScanLocalApproved) == 0 { if strings.Compare("no", result.SyncScanLocalApproved) == 0 {
// skip this file // skip this file
@ -441,6 +448,8 @@ func (t *SyncTask) skipPanFile(file *PanFileItem) bool {
DriveFileType: file.FileType, DriveFileType: file.FileType,
DriveFileUpdatedAt: file.UpdatedAt, DriveFileUpdatedAt: file.UpdatedAt,
} }
t.pluginMutex.Lock()
defer t.pluginMutex.Unlock()
if result, er := t.plugin.SyncScanPanFilePrepareCallback(plugins.GetContext(t.panUser), pluginParam); er == nil && result != nil { if result, er := t.plugin.SyncScanPanFilePrepareCallback(plugins.GetContext(t.panUser), pluginParam); er == nil && result != nil {
if strings.Compare("no", result.SyncScanPanApproved) == 0 { if strings.Compare("no", result.SyncScanPanApproved) == 0 {
// skip this file // skip this file