mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-02-02 21:27:15 +08:00
fix sync prepare error
This commit is contained in:
parent
6669b64027
commit
57e2ecdb72
@ -139,22 +139,28 @@ mode - 模式,支持三种: upload(备份本地文件到云盘),download(备
|
||||
var task *syncdrive.SyncTask
|
||||
localDir := c.String("ldir")
|
||||
panDir := c.String("pdir")
|
||||
mode := c.String("upload")
|
||||
mode := c.String("mode")
|
||||
if localDir != "" && panDir != "" {
|
||||
if b, e := utils.PathExists(localDir); e == nil {
|
||||
if !b {
|
||||
fmt.Println("本地文件夹不存在:", localDir)
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
fmt.Println("本地文件夹不存在:", localDir)
|
||||
return nil
|
||||
}
|
||||
//if b, e := utils.PathExists(localDir); e == nil {
|
||||
// if !b {
|
||||
// fmt.Println("本地文件夹不存在:", localDir)
|
||||
// return nil
|
||||
// }
|
||||
//} else {
|
||||
// fmt.Println("本地文件夹不存在:", localDir)
|
||||
// return nil
|
||||
//}
|
||||
task = &syncdrive.SyncTask{}
|
||||
task.LocalFolderPath = path.Clean(strings.ReplaceAll(localDir, "\\", "/"))
|
||||
task.PanFolderPath = panDir
|
||||
task.Mode = syncdrive.SyncMode(mode)
|
||||
if task.Mode == "" {
|
||||
task.Mode = syncdrive.UploadOnly
|
||||
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.Name = path.Base(task.LocalFolderPath)
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/tickstep/aliyunpan-api/aliyunpan"
|
||||
"github.com/tickstep/aliyunpan-api/aliyunpan/apierror"
|
||||
"github.com/tickstep/aliyunpan/internal/config"
|
||||
"github.com/tickstep/aliyunpan/internal/plugins"
|
||||
"github.com/tickstep/aliyunpan/internal/utils"
|
||||
@ -117,6 +118,19 @@ func (t *SyncTask) Start() error {
|
||||
}
|
||||
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 {
|
||||
t.fileActionTaskManager = NewFileActionTaskManager(t, t.maxDownloadRate, t.maxUploadRate)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user