From e24ba2aadc3c8a7fe4175eda452c6c59989a6b0c Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 2 May 2021 21:53:43 -0700 Subject: [PATCH] filer: delete specific tags fix https://github.com/chrislusf/seaweedfs/issues/2041 --- weed/server/filer_server_handlers_tagging.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/weed/server/filer_server_handlers_tagging.go b/weed/server/filer_server_handlers_tagging.go index 50b3a2c06..70b5327d6 100644 --- a/weed/server/filer_server_handlers_tagging.go +++ b/weed/server/filer_server_handlers_tagging.go @@ -78,11 +78,27 @@ func (fs *FilerServer) DeleteTaggingHandler(w http.ResponseWriter, r *http.Reque existingEntry.Extended = make(map[string][]byte) } + // parse out tags to be deleted + toDelete := strings.Split(r.URL.Query().Get("tagging"), ",") + deletions := make(map[string]struct{}) + for _, deletion := range toDelete { + deletions[deletion] = struct{}{} + } + + // delete all tags or specific tags hasDeletion := false for header, _ := range existingEntry.Extended { if strings.HasPrefix(header, needle.PairNamePrefix) { - delete(existingEntry.Extended, header) - hasDeletion = true + if len(deletions) == 0 { + delete(existingEntry.Extended, header) + hasDeletion = true + } else { + tag := header[len(needle.PairNamePrefix):] + if _, found := deletions[tag]; found { + delete(existingEntry.Extended, header) + hasDeletion = true + } + } } }