Skip to content

Commit

Permalink
fix(189pc,baidu_photo): source file not closed
Browse files Browse the repository at this point in the history
  • Loading branch information
foxxorcat committed Sep 12, 2022
1 parent 6b5236f commit 53e08e7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions drivers/189pc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ func (y *Yun189PC) FastUpload(ctx context.Context, dstDir model.Obj, file model.
_ = tempFile.Close()
_ = os.Remove(tempFile.Name())
}()
file.SetReadCloser(tempFile)

const DEFAULT int64 = 10485760
count := int(math.Ceil(float64(file.GetSize()) / float64(DEFAULT)))
Expand All @@ -526,7 +525,7 @@ func (y *Yun189PC) FastUpload(ctx context.Context, dstDir model.Obj, file model.
}

silceMd5.Reset()
if _, err := io.CopyN(io.MultiWriter(fileMd5, silceMd5), file, DEFAULT); err != nil && err != io.EOF && err != io.ErrUnexpectedEOF {
if _, err := io.CopyN(io.MultiWriter(fileMd5, silceMd5), tempFile, DEFAULT); err != nil && err != io.EOF && err != io.ErrUnexpectedEOF {
return err
}
md5Byte := silceMd5.Sum(nil)
Expand Down Expand Up @@ -596,7 +595,7 @@ func (y *Yun189PC) FastUpload(ctx context.Context, dstDir model.Obj, file model.
SetContext(ctx).
SetQueryParams(clientSuffix()).
SetHeaders(ParseHttpHeader(uploadData.RequestHeader)).
SetBody(io.LimitReader(file, DEFAULT)).
SetBody(io.LimitReader(tempFile, DEFAULT)).
Put(uploadData.RequestURL)
if err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions drivers/baidu_photo/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ func (d *BaiduPhoto) Put(ctx context.Context, dstDir model.Obj, stream model.Fil
_ = tempFile.Close()
_ = os.Remove(tempFile.Name())
}()
stream.SetReadCloser(tempFile)

// 计算需要的数据
const DEFAULT = 1 << 22
Expand All @@ -195,7 +194,7 @@ func (d *BaiduPhoto) Put(ctx context.Context, dstDir model.Obj, stream model.Fil
return ctx.Err()
default:
}
_, err := io.CopyN(io.MultiWriter(fileMd5, sliceMd5, slicemd52Write), stream, DEFAULT)
_, err := io.CopyN(io.MultiWriter(fileMd5, sliceMd5, slicemd52Write), tempFile, DEFAULT)
if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF {
return err
}
Expand Down

0 comments on commit 53e08e7

Please sign in to comment.