fix that the folder will created repeatly while uploading file

This commit is contained in:
xiaoyaofenfen 2023-01-03 10:57:08 +08:00
parent c9c33217d2
commit 5b22c4400a
2 changed files with 5 additions and 0 deletions

View File

@ -451,6 +451,7 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
// 这样空文件夹也可以正确上传
saveFilePath := subSavePath
if saveFilePath != "/" {
folderCreateMutex.Lock()
fmt.Printf("正在检测和创建云盘文件夹: %s\n", saveFilePath)
_, apierr1 := activeUser.PanClient().FileInfoByPath(opt.DriveId, saveFilePath)
time.Sleep(1 * time.Second)
@ -461,6 +462,7 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
fmt.Printf("创建云盘文件夹失败: %s\n", saveFilePath)
}
}
folderCreateMutex.Unlock()
}
}
return nil

View File

@ -350,6 +350,7 @@ StepUploadPrepareUpload:
// 创建云盘文件夹
saveFilePath = path.Dir(utu.SavePath)
if saveFilePath != "/" {
utu.FolderCreateMutex.Lock()
fmt.Printf("[%s] %s 正在检测和创建云盘文件夹: %s\n", utu.taskInfo.Id(), time.Now().Format("2006-01-02 15:04:06"), saveFilePath)
fe, apierr1 := utu.PanClient.FileInfoByPath(utu.DriveId, saveFilePath)
time.Sleep(1 * time.Second)
@ -361,6 +362,7 @@ StepUploadPrepareUpload:
if apierr != nil || rs.FileId == "" {
result.Err = apierr
result.ResultMessage = "创建云盘文件夹失败"
utu.FolderCreateMutex.Unlock()
return
}
logger.Verbosef("[%s] %s 创建云盘文件夹成功\n", utu.taskInfo.Id(), time.Now().Format("2006-01-02 15:04:06"))
@ -368,6 +370,7 @@ StepUploadPrepareUpload:
rs = &aliyunpan.MkdirResult{}
rs.FileId = fe.FileId
}
utu.FolderCreateMutex.Unlock()
} else {
rs = &aliyunpan.MkdirResult{}
rs.FileId = ""