fix(fs): fix fd leaking issue

This commit is contained in:
hexxa 2021-09-13 15:15:03 +08:00 committed by Hexxa
parent fb9de35e81
commit 50f66704b1
6 changed files with 96 additions and 39 deletions

View file

@ -8,6 +8,7 @@ import (
"github.com/ihexxa/quickshare/src/worker"
)
const MsgTypeSha1 = "sha1"
type Sha1Params struct {
@ -25,6 +26,12 @@ func (h *FileHandlers) genSha1(msg worker.IMsg) error {
if err != nil {
return fmt.Errorf("fail to get reader: %s", err)
}
defer func() {
err := h.deps.FS().CloseReader(taskInputs.FilePath)
if err != nil {
h.deps.Log().Errorf("failed to close file: %s", err)
}
}()
hasher := sha1.New()
buf := make([]byte, 4096)