summaryrefslogtreecommitdiff
path: root/internal/media/processingemoji.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/media/processingemoji.go')
-rw-r--r--internal/media/processingemoji.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/internal/media/processingemoji.go b/internal/media/processingemoji.go
index 2a3cd1613..c8c8d18c8 100644
--- a/internal/media/processingemoji.go
+++ b/internal/media/processingemoji.go
@@ -29,6 +29,7 @@ import (
"time"
"codeberg.org/gruf/go-store/kv"
+ "github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/uris"
@@ -169,6 +170,15 @@ func (p *ProcessingEmoji) store(ctx context.Context) error {
return fmt.Errorf("store: error executing data function: %s", err)
}
+ // defer closing the reader when we're done with it
+ defer func() {
+ if rc, ok := reader.(io.ReadCloser); ok {
+ if err := rc.Close(); err != nil {
+ logrus.Errorf("store: error closing readcloser: %s", err)
+ }
+ }
+ }()
+
// extract no more than 261 bytes from the beginning of the file -- this is the header
firstBytes := make([]byte, maxFileHeaderBytes)
if _, err := reader.Read(firstBytes); err != nil {
@@ -205,13 +215,6 @@ func (p *ProcessingEmoji) store(ctx context.Context) error {
return fmt.Errorf("store: error storing stream: %s", err)
}
- // if the original reader is a readcloser, close it since we're done with it now
- if rc, ok := reader.(io.ReadCloser); ok {
- if err := rc.Close(); err != nil {
- return fmt.Errorf("store: error closing readcloser: %s", err)
- }
- }
-
p.read = true
if p.postData != nil {