Skip to content

Commit

Permalink
Fix concurrent registration of mimetypes (#2077)
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic authored Sep 16, 2021
1 parent d83f20c commit 3cb3c21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-concurrent-mimetype-map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Fix concurrent registration of mimetypes

We fixed registering mimetypes in the mime package when starting multiple storage providers in the same process.

https://github.com/cs3org/reva/pull/2077
12 changes: 8 additions & 4 deletions pkg/mime/mime.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@ package mime

import (
"path"
"sync"

gomime "github.com/cubewise-code/go-mime"
)

const defaultMimeDir = "httpd/unix-directory"

var mimes map[string]string
var mimes sync.Map

func init() {
mimes = map[string]string{}
mimes = sync.Map{}
}

// RegisterMime is a package level function that registers
// a mime type with the given extension.
// TODO(labkode): check that we do not override mime type mappings?
func RegisterMime(ext, mime string) {
mimes[ext] = mime
mimes.Store(ext, mime)
}

// Detect returns the mimetype associated with the given filename.
Expand All @@ -61,5 +62,8 @@ func Detect(isDir bool, fn string) string {
}

func getCustomMime(ext string) string {
return mimes[ext]
if m, ok := mimes.Load(ext); ok {
return m.(string)
}
return ""
}

0 comments on commit 3cb3c21

Please sign in to comment.