Skip to content

Commit

Permalink
修复取消分享失败
Browse files Browse the repository at this point in the history
  • Loading branch information
iikira committed Sep 3, 2018
1 parent e63018b commit 7fc9912
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
21 changes: 11 additions & 10 deletions internal/pcscommand/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,27 +298,28 @@ func RunDownload(paths []string, options *DownloadOptions) {
return
}

fmt.Fprintf(options.Out, "[%d] %s, %s, 重试 %d/%d\n", task.ID, errManifest, err, task.retry, task.MaxRetry)
// 未达到失败重试最大次数, 将任务推送到队列末尾
if task.retry < task.MaxRetry {
task.retry++
fmt.Fprintf(options.Out, "[%d] %s, %s, 重试 %d/%d\n", task.ID, errManifest, err, task.retry, task.MaxRetry)
dlist.Append(task)
time.Sleep(3 * time.Duration(task.retry) * time.Second)
} else {
failedList = append(failedList, task.path)
}

switch err {
case ErrChecksumFailed:
// 删去旧的文件, 重新下载
rerr := os.Remove(task.savePath)
if rerr != nil {
fmt.Fprintf(options.Out, "[%d] 移除文件失败, %s\n", task.ID, rerr)
fmt.Fprintf(options.Out, "[%d] 删除校验失败的文件出错, %s\n", task.ID, rerr)
failedList = append(failedList, task.path)
return
}
}

// 未达到失败重试最大次数, 将任务推送到队列末尾
if task.retry < task.MaxRetry {
task.retry++
dlist.Append(task)
} else {
failedList = append(failedList, task.path)
fmt.Fprintf(options.Out, "[%d] 已删除校验失败的文件\n", task.ID)
}
time.Sleep(3 * time.Duration(task.retry) * time.Second)
}
startTime = time.Now()
wg = waitgroup.NewWaitGroup(options.Load)
Expand Down
5 changes: 4 additions & 1 deletion internal/pcscommand/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/iikira/BaiduPCS-Go/baidupcs"
"github.com/iikira/BaiduPCS-Go/internal/pcsconfig"
"github.com/iikira/BaiduPCS-Go/pcstable"
"github.com/iikira/BaiduPCS-Go/requester"
"github.com/iikira/baidu-tools/pan"
"net/url"
"os"
Expand Down Expand Up @@ -124,7 +125,8 @@ func getShareDLink(pcspath string) (dlink string) {

func getLink(shareID int64, shareLink, passwd, rootSharePath, filePath string) (dlink string) {
sInfo := pan.NewSharedInfo(shareLink)
sInfo.Client = pcsconfig.Config.HTTPClient()
sInfo.Client = requester.NewHTTPClient()
sInfo.Client.SetHTTPSecure(pcsconfig.Config.EnableHTTPS())

if passwd != "" {
err := sInfo.Auth(passwd)
Expand All @@ -136,6 +138,7 @@ func getLink(shareID int64, shareLink, passwd, rootSharePath, filePath string) (

uk, pcsError := GetBaiduPCS().UK()
if pcsError != nil {
// 获取UK失败, 从分享链接获取信息
pcsCommandVerbose.Warn(pcsError.Error())
err := sInfo.InitInfo()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions internal/pcscommand/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,10 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
}
}

fmt.Printf("[%d] %s, %s, 重试 %d/%d\n", task.ID, errManifest, pcsError, task.retry, task.MaxRetry)

// 未达到失败重试最大次数, 将任务推送到队列末尾
if task.retry < task.MaxRetry {
task.retry++
fmt.Printf("[%d] %s, %s, 重试 %d/%d\n", task.ID, errManifest, pcsError, task.retry, task.MaxRetry)
ulist.PushBack(task)
time.Sleep(3 * time.Duration(task.retry) * time.Second)
} else {
Expand Down
2 changes: 1 addition & 1 deletion pcsutil/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func IntToBool(i int) bool {
// SliceInt64ToString []int64 转换为 []string
func SliceInt64ToString(si []int64) (ss []string) {
ss = make([]string, 0, len(si))
for k := range ss {
for k := range si {
ss = append(ss, strconv.FormatInt(si[k], 10))
}
return ss
Expand Down

0 comments on commit 7fc9912

Please sign in to comment.