Skip to content

Commit

Permalink
fix: 修复上传长度为零的文件出现的错误 (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
arrebole authored Mar 28, 2023
1 parent 4d74d4f commit d95719d
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,34 +474,36 @@ func (sess *Session) putFileWithProgress(barId int, localPath, upPath string, lo

idx := -1
if isVerbose {
var bar *uiprogress.Bar
bar, idx = AddBar(barId, int(localInfo.Size()))
bar = bar.AppendCompleted()
bar.PrependFunc(func(b *uiprogress.Bar) string {
status := "WAIT"
if b.Current() == b.Total {
status = "OK"
}
name := leftAlign(shortPath(upPath, 40), 40)
if err != nil {
b.Set(bar.Total)
return fmt.Sprintf("%s ERR %s", name, err)
}
return fmt.Sprintf("%s %s", name, rightAlign(status, 4))
})
wReader := &ProgressReader{fd: fd}
cfg.Reader = wReader
wg.Add(1)
go func() {
defer wg.Done()
for err == nil {
if wReader.Copyed() == bar.Total {
if localInfo.Size() > 0 {
var bar *uiprogress.Bar
bar, idx = AddBar(barId, int(localInfo.Size()))
bar = bar.AppendCompleted()
bar.PrependFunc(func(b *uiprogress.Bar) string {
status := "WAIT"
if b.Current() == b.Total {
status = "OK"
}
name := leftAlign(shortPath(upPath, 40), 40)
if err != nil {
b.Set(bar.Total)
return fmt.Sprintf("%s ERR %s", name, err)
}
return fmt.Sprintf("%s %s", name, rightAlign(status, 4))
})
wReader := &ProgressReader{fd: fd}
cfg.Reader = wReader
wg.Add(1)
go func() {
defer wg.Done()
for err == nil {
if wReader.Copyed() == bar.Total {
bar.Set(wReader.Copyed())
return
}
bar.Set(wReader.Copyed())
return
}
bar.Set(wReader.Copyed())
}
}()
}()
}
} else {
log.Printf("file: %s, Start\n", upPath)
if localInfo.Size() >= MinResumePutFileSize {
Expand Down

0 comments on commit d95719d

Please sign in to comment.