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/enhancing delete 486 #880

Merged
merged 9 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
enhance object delete
update delete all,avoid misusing curl
  • Loading branch information
jiangshaohua committed Dec 23, 2022
commit 7b3f6c33c2b38d8eb40f13c85e4015054ffc8739
3 changes: 2 additions & 1 deletion cmd/client/command/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package command

import (
"errors"
"fmt"
"net/http"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -121,7 +122,7 @@ func deleteObjectCmd() *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {

coderabbit214 marked this conversation as resolved.
Show resolved Hide resolved
if allFlag {
handleRequest(http.MethodDelete, makeURL(objectsURL), nil, cmd)
handleRequest(http.MethodDelete, makeURL(objectsURL+fmt.Sprintf("?all=%v", true)), nil, cmd)
return
}

Expand Down
20 changes: 12 additions & 8 deletions pkg/api/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *Server) objectAPIEntries() []*Entry {
{
Path: ObjectPrefix,
coderabbit214 marked this conversation as resolved.
Show resolved Hide resolved
Method: "DELETE",
Handler: s.deleteAllObject,
Handler: s.deleteObjects,
},
{
Path: StatusObjectPrefix,
Expand Down Expand Up @@ -156,16 +156,20 @@ func (s *Server) deleteObject(w http.ResponseWriter, r *http.Request) {
s.upgradeConfigVersion(w, r)
}

func (s *Server) deleteAllObject(w http.ResponseWriter, r *http.Request) {
s.Lock()
defer s.Unlock()
func (s *Server) deleteObjects(w http.ResponseWriter, r *http.Request) {
allFlag := r.URL.Query().Get("all")
if allFlag == "true" {
s.Lock()
defer s.Unlock()

specs := s._listObjects()
for _, spec := range specs {
s._deleteObject(spec.Name())
specs := s._listObjects()
for _, spec := range specs {
s._deleteObject(spec.Name())
}

s.upgradeConfigVersion(w, r)
}

coderabbit214 marked this conversation as resolved.
Show resolved Hide resolved
s.upgradeConfigVersion(w, r)
}

func (s *Server) getObject(w http.ResponseWriter, r *http.Request) {
Expand Down