fix sync prepare error

This commit is contained in:
tickstep 2022-06-17 23:37:32 +08:00
parent 6669b64027
commit 57e2ecdb72
2 changed files with 32 additions and 12 deletions

View File

@ -139,22 +139,28 @@ mode - 模式,支持三种: upload(备份本地文件到云盘),download(备
var task *syncdrive.SyncTask var task *syncdrive.SyncTask
localDir := c.String("ldir") localDir := c.String("ldir")
panDir := c.String("pdir") panDir := c.String("pdir")
mode := c.String("upload") mode := c.String("mode")
if localDir != "" && panDir != "" { if localDir != "" && panDir != "" {
if b, e := utils.PathExists(localDir); e == nil { //if b, e := utils.PathExists(localDir); e == nil {
if !b { // if !b {
fmt.Println("本地文件夹不存在:", localDir) // fmt.Println("本地文件夹不存在:", localDir)
return nil // return nil
} // }
} else { //} else {
fmt.Println("本地文件夹不存在:", localDir) // fmt.Println("本地文件夹不存在:", localDir)
return nil // return nil
} //}
task = &syncdrive.SyncTask{} task = &syncdrive.SyncTask{}
task.LocalFolderPath = path.Clean(strings.ReplaceAll(localDir, "\\", "/")) task.LocalFolderPath = path.Clean(strings.ReplaceAll(localDir, "\\", "/"))
task.PanFolderPath = panDir task.PanFolderPath = panDir
task.Mode = syncdrive.SyncMode(mode) task.Mode = syncdrive.UploadOnly
if task.Mode == "" { if mode == string(syncdrive.UploadOnly) {
task.Mode = syncdrive.UploadOnly
} else if mode == string(syncdrive.DownloadOnly) {
task.Mode = syncdrive.DownloadOnly
} else if mode == string(syncdrive.SyncTwoWay) {
task.Mode = syncdrive.SyncTwoWay
} else {
task.Mode = syncdrive.UploadOnly task.Mode = syncdrive.UploadOnly
} }
task.Name = path.Base(task.LocalFolderPath) task.Name = path.Base(task.LocalFolderPath)

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/tickstep/aliyunpan-api/aliyunpan" "github.com/tickstep/aliyunpan-api/aliyunpan"
"github.com/tickstep/aliyunpan-api/aliyunpan/apierror"
"github.com/tickstep/aliyunpan/internal/config" "github.com/tickstep/aliyunpan/internal/config"
"github.com/tickstep/aliyunpan/internal/plugins" "github.com/tickstep/aliyunpan/internal/plugins"
"github.com/tickstep/aliyunpan/internal/utils" "github.com/tickstep/aliyunpan/internal/utils"
@ -117,6 +118,19 @@ func (t *SyncTask) Start() error {
} }
t.setupDb() t.setupDb()
// check root dir
if b, e := utils.PathExists(t.LocalFolderPath); e == nil {
if !b {
// create local root folder
os.MkdirAll(t.LocalFolderPath, 0755)
}
}
if _, er := t.panClient.FileInfoByPath(t.DriveId, t.PanFolderPath); er != nil {
if er.Code == apierror.ApiCodeFileNotFoundCode {
t.panClient.MkdirByFullPath(t.DriveId, t.PanFolderPath)
}
}
if t.fileActionTaskManager == nil { if t.fileActionTaskManager == nil {
t.fileActionTaskManager = NewFileActionTaskManager(t, t.maxDownloadRate, t.maxUploadRate) t.fileActionTaskManager = NewFileActionTaskManager(t, t.maxDownloadRate, t.maxUploadRate)
} }