Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix concurrent registration of mimetypes #2077

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ""
}