Skip to content

Commit 0a33775

Browse files
g199209xhofe
authored andcommitted
fix(quark): upload file integer divide by zero panic. (close #3076 pr #3077)
1 parent 26fe0a7 commit 0a33775

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/quark/driver.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ func (d *Quark) Put(ctx context.Context, dstDir model.Obj, stream model.FileStre
175175
var bytes []byte
176176
md5s := make([]string, 0)
177177
defaultBytes := make([]byte, partSize)
178-
left := stream.GetSize()
178+
total := stream.GetSize()
179+
left := total
179180
partNumber := 1
180-
sizeDivide100 := stream.GetSize() / 100
181181
for left > 0 {
182182
if utils.IsCanceled(ctx) {
183183
return ctx.Err()
@@ -191,7 +191,7 @@ func (d *Quark) Put(ctx context.Context, dstDir model.Obj, stream model.FileStre
191191
if err != nil {
192192
return err
193193
}
194-
left -= int64(partSize)
194+
left -= int64(len(bytes))
195195
log.Debugf("left: %d", left)
196196
m, err := d.upPart(ctx, pre, stream.GetMimetype(), partNumber, bytes)
197197
//m, err := driver.UpPart(pre, file.GetMIMEType(), partNumber, bytes, account, md5Str, sha1Str)
@@ -203,7 +203,7 @@ func (d *Quark) Put(ctx context.Context, dstDir model.Obj, stream model.FileStre
203203
}
204204
md5s = append(md5s, m)
205205
partNumber++
206-
up(100 - int(left/sizeDivide100))
206+
up(int(100 * (total - left) / total))
207207
}
208208
err = d.upCommit(pre, md5s)
209209
if err != nil {

0 commit comments

Comments
 (0)