Skip to content

Commit

Permalink
fix #548, 上传文件会清除上传状态过期的任务了
Browse files Browse the repository at this point in the history
  • Loading branch information
iikira committed Nov 20, 2018
1 parent 8e94e8c commit 829eb1e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
5 changes: 2 additions & 3 deletions baidupcs/extends.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/hex"
"errors"
"github.com/iikira/BaiduPCS-Go/baidupcs/pcserror"
"github.com/iikira/BaiduPCS-Go/pcsutil/converter"
"github.com/iikira/BaiduPCS-Go/pcsutil/escaper"
"github.com/iikira/BaiduPCS-Go/requester/downloader"
"io"
Expand Down Expand Up @@ -65,7 +64,7 @@ func (pcs *BaiduPCS) getLocateDownloadLink(pcspath string) (link string, pcsErro
func (pcs *BaiduPCS) ExportByFileInfo(finfo *FileDirectory) (rinfo *RapidUploadInfo, pcsError pcserror.Error) {
errInfo := pcserror.NewPCSErrorInfo(OperationExportFileInfo)
errInfo.ErrType = pcserror.ErrTypeOthers
if finfo.Size > 20*converter.GB {
if finfo.Size > MaxRapidUploadSize {
errInfo.Err = ErrFileTooLarge
return nil, errInfo
}
Expand Down Expand Up @@ -252,7 +251,7 @@ func (pcs *BaiduPCS) FixMD5ByFileInfo(finfo *FileDirectory) (pcsError pcserror.E
return errInfo
}

if finfo.Size > 20*converter.GB { // 文件大于20GB
if finfo.Size > MaxRapidUploadSize { // 文件大于20GB
errInfo.Err = ErrFileTooLarge
return errInfo
}
Expand Down
2 changes: 2 additions & 0 deletions baidupcs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const (
MaxUploadBlockSize = 2 * converter.GB
// MinUploadBlockSize 最小的上传的文件分片大小
MinUploadBlockSize = 4 * converter.MB
// MaxRapidUploadSize 秒传文件支持的最大文件大小
MaxRapidUploadSize = 20 * converter.GB
// RecommendUploadBlockSize 推荐的上传的文件分片大小
RecommendUploadBlockSize = 1 * converter.GB
// SliceMD5Size 计算 slice-md5 所需的长度
Expand Down
26 changes: 20 additions & 6 deletions internal/pcscommand/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
}
defer task.uploadInfo.Close() // 关闭文件

// 步骤控制
var (
panDir, panFile = path.Split(task.savePath)
)
Expand All @@ -261,7 +260,13 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
goto stepControl
}

stepControl:
if task.uploadInfo.Length > baidupcs.MaxRapidUploadSize {
fmt.Printf("[%d] 文件超过20GB, 无法使用秒传功能, 跳过秒传...\n", task.ID)
task.step = StepUploadUpload
goto stepControl
}

stepControl: // 步骤控制
switch task.step {
case StepUploadRapidUpload:
goto stepUploadRapidUpload
Expand Down Expand Up @@ -309,7 +314,6 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
// do nothing
}

// 经过测试, 秒传文件并非需要前256kb切片的md5值, 只需格式符合即可
task.uploadInfo.SliceMD5Sum()

// 经测试, 文件的 crc32 值并非秒传文件所必需
Expand Down Expand Up @@ -389,11 +393,21 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
muer.OnError(func(err error) {
close(exitChan)
pcsError, ok := err.(pcserror.Error)
if ok {
handleTaskErr(task, "上传文件失败", pcsError)
if !ok {
fmt.Printf("[%d] 上传文件错误: %s\n", task.ID, err)
return
}
fmt.Printf("[%d] 上传文件错误: %s\n", task.ID, err)

switch pcsError.GetRemoteErrCode() {
case 31363: // block miss in superfile2, 上传状态过期
uploadDatabase.Delete(&task.uploadInfo.LocalFileMeta)
uploadDatabase.Save()
fmt.Printf("[%d] 上传文件错误: 上传状态过期, 请重新上传\n", task.ID)
return
}

handleTaskErr(task, "上传文件失败", pcsError)
return
})
muer.Execute()
}
Expand Down

0 comments on commit 829eb1e

Please sign in to comment.