Skip to content

Commit

Permalink
feature: 重新恢复下载文件夹时,跳过已经下载好的文件 (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
arrebole authored Apr 11, 2023
1 parent 6cff07c commit 8c30c06
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (sess *Session) Ls(upPath string, match *MatchConfig, maxItems int, isDesc
}
}

func (sess *Session) getDir(upPath, localPath string, match *MatchConfig, workers int) error {
func (sess *Session) getDir(upPath, localPath string, match *MatchConfig, workers int, resume bool) error {
if err := os.MkdirAll(localPath, 0755); err != nil {
return err
}
Expand All @@ -298,8 +298,26 @@ func (sess *Session) getDir(upPath, localPath string, match *MatchConfig, worker
if fInfo.IsDir {
os.MkdirAll(lpath, 0755)
} else {
isContinue := resume

// 判断本地文件是否存在
// 如果存在,大小一致 并且本地文件的最后修改时间大于云端文件的最后修改时间 则跳过该下载
// 如果云端文件最后的修改时间大于本地文件的创建时间,则强制重新下载
stat, err := os.Stat(lpath)
if err == nil {
if stat.Size() == fInfo.Size && stat.ModTime().After(fInfo.Time) {
continue
}
if stat.Size() > fInfo.Size {
isContinue = false
}
if fInfo.Time.After(stat.ModTime()) {
isContinue = false
}
}

for i := 1; i <= MaxRetry; i++ {
id, e = sess.getFileWithProgress(id, fpath, lpath, fInfo, 1, false)
id, e = sess.getFileWithProgress(id, fpath, lpath, fInfo, 1, isContinue)
if e == nil {
break
}
Expand Down Expand Up @@ -418,7 +436,7 @@ func (sess *Session) Get(upPath, localPath string, match *MatchConfig, workers i
}
}
}
sess.getDir(upPath, localPath, match, workers)
sess.getDir(upPath, localPath, match, workers, resume)
} else {
if isDir {
localPath = filepath.Join(localPath, path.Base(upPath))
Expand Down

0 comments on commit 8c30c06

Please sign in to comment.