diff --git a/changelog/unreleased/fix-concurrent-mimetype-map.md b/changelog/unreleased/fix-concurrent-mimetype-map.md new file mode 100644 index 0000000000..82ea865422 --- /dev/null +++ b/changelog/unreleased/fix-concurrent-mimetype-map.md @@ -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 diff --git a/pkg/mime/mime.go b/pkg/mime/mime.go index 3e8a084443..6908450308 100644 --- a/pkg/mime/mime.go +++ b/pkg/mime/mime.go @@ -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. @@ -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 "" }