fix sync download bug

This commit is contained in:
tickstep 2022-06-04 16:45:45 +08:00
parent 8955eeec92
commit ab6290e7a3
2 changed files with 22 additions and 27 deletions

View File

@ -42,8 +42,8 @@ func (f *FileActionTask) HashCode() string {
}
func (f *FileActionTask) DoAction(ctx context.Context) error {
fmt.Println("\nfile action task")
fmt.Println(f.syncItem)
logger.Verboseln("file action task")
logger.Verboseln(f.syncItem)
if f.syncItem.Action == SyncFileActionUpload {
if e := f.uploadFile(); e != nil {
return e
@ -93,12 +93,12 @@ func (f *FileActionTask) DoAction(ctx context.Context) error {
func (f *FileActionTask) downloadFile() error {
// check local file existed or not
//if b, e := utils.PathExists(f.syncItem.getLocalFileFullPath()); e == nil && b {
// // file existed
// logger.Verbosef("delete local old file")
// os.Remove(f.syncItem.getLocalFileFullPath())
// time.Sleep(200 * time.Millisecond)
//}
if b, e := utils.PathExists(f.syncItem.getLocalFileFullPath()); e == nil && b {
// file existed
logger.Verbosef("delete local old file")
os.Remove(f.syncItem.getLocalFileFullPath())
time.Sleep(200 * time.Millisecond)
}
durl, apierr := f.panClient.GetFileDownloadUrl(&aliyunpan.GetFileDownloadUrlParam{
DriveId: f.syncItem.PanFile.DriveId,

View File

@ -79,24 +79,7 @@ func (t *SyncTask) String() string {
return builder.String()
}
func (t *SyncTask) setup() error {
t.localFileDb = NewLocalSyncDb(t.localSyncDbFullPath())
t.panFileDb = NewPanSyncDb(t.panSyncDbFullPath())
t.syncFileDb = NewSyncFileDb(t.syncFileDbFullPath())
if _, e := t.localFileDb.Open(); e != nil {
return e
}
if _, e := t.panFileDb.Open(); e != nil {
return e
}
return nil
}
// Start 启动同步任务
func (t *SyncTask) Start() error {
if t.ctx != nil {
return fmt.Errorf("task have starting")
}
func (t *SyncTask) setupDb() error {
t.localFileDb = NewLocalSyncDb(t.localSyncDbFullPath())
t.panFileDb = NewPanSyncDb(t.panSyncDbFullPath())
t.syncFileDb = NewSyncFileDb(t.syncFileDbFullPath())
@ -109,6 +92,15 @@ func (t *SyncTask) Start() error {
if _, e := t.syncFileDb.Open(); e != nil {
return e
}
return nil
}
// Start 启动同步任务
func (t *SyncTask) Start() error {
if t.ctx != nil {
return fmt.Errorf("task have starting")
}
t.setupDb()
if t.fileActionTaskManager == nil {
t.fileActionTaskManager = NewFileActionTaskManager(t)
@ -123,7 +115,10 @@ func (t *SyncTask) Start() error {
go t.scanLocalFile(t.ctx)
go t.scanPanFile(t.ctx)
//t.fileActionTaskManager.Start()
// start file sync manager
if e := t.fileActionTaskManager.Start(); e != nil {
return e
}
return nil
}