From b5183612be85ec2f1102026229f224e610473676 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Sun, 9 Jan 2022 22:06:31 -0500 Subject: [PATCH] Fix attachment pruning logging; .mp4 extension issue --- server/file_cache.go | 19 +++++-------------- util/util.go | 2 ++ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/server/file_cache.go b/server/file_cache.go index 04ae76e4..40346474 100644 --- a/server/file_cache.go +++ b/server/file_cache.go @@ -71,13 +71,12 @@ func (c *fileCache) Write(id string, in io.Reader, limiters ...*util.Limiter) (i } func (c *fileCache) Remove(ids ...string) error { - var firstErr error for _, id := range ids { - if err := c.removeFile(id); err != nil { - if firstErr == nil { - firstErr = err // Continue despite error; we want to delete as many as we can - } + if !fileIDRegex.MatchString(id) { + return errInvalidFileID } + file := filepath.Join(c.dir, id) + _ = os.Remove(file) // Best effort delete } size, err := dirSize(c.dir) if err != nil { @@ -86,15 +85,7 @@ func (c *fileCache) Remove(ids ...string) error { c.mu.Lock() c.totalSizeCurrent = size c.mu.Unlock() - return firstErr -} - -func (c *fileCache) removeFile(id string) error { - if !fileIDRegex.MatchString(id) { - return errInvalidFileID - } - file := filepath.Join(c.dir, id) - return os.Remove(file) + return nil } func (c *fileCache) Size() int64 { diff --git a/util/util.go b/util/util.go index 887443bf..ae4315b3 100644 --- a/util/util.go +++ b/util/util.go @@ -173,6 +173,8 @@ func ExtensionByType(contentType string) string { switch contentType { case "image/jpeg": return ".jpg" + case "video/mp4": + return ".mp4" default: exts, err := mime.ExtensionsByType(contentType) if err == nil && len(exts) > 0 && extRegex.MatchString(exts[0]) {