Skip to content

Commit

Permalink
feat(remote): add support for ref removes
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 committed Aug 29, 2019
1 parent a969b9a commit e2a6d3a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
3 changes: 3 additions & 0 deletions remote/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ func removeDatasetHTTP(ctx context.Context, params map[string]string, remoteAddr
}

if res.StatusCode != http.StatusOK {
if data, err := ioutil.ReadAll(res.Body); err == nil {
log.Error("HTTP server remove error response: ", string(data))
}
return fmt.Errorf("failed to remove dataset from remote")
}

Expand Down
35 changes: 28 additions & 7 deletions remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,23 @@ func (r *Remote) ResolveHeadRef(ctx context.Context, peername, name string) (*re
return ref, err
}

// RemoveDataset handles requests to remove a dataset
func (r *Remote) RemoveDataset(ctx context.Context, params map[string]string) error {
// TODO (b5):
return fmt.Errorf("not yet implemented: removing dataset revisions")
// RemoveDatasetRef handles requests to remove a dataset
func (r *Remote) RemoveDatasetRef(ctx context.Context, params map[string]string) error {
ref, err := r.refFromMeta(params)
if err != nil {
return err
}
log.Debug("remove dataset ", ref)

if err := repo.CanonicalizeDatasetRef(r.node.Repo, &ref); err != nil {
if err == repo.ErrNotFound {
err = nil
} else {
return err
}
}

return r.node.Repo.DeleteRef(ref)
}

func (r *Remote) pushPreCheck(ctx context.Context, info dag.Info, meta map[string]string) error {
Expand Down Expand Up @@ -268,9 +281,17 @@ func (r *Remote) RefsHTTPHandler() http.HandlerFunc {
w.Write(res)
return
case "DELETE":
// TODO (b5) - handle delete
w.WriteHeader(http.StatusNotImplemented)
w.Write([]byte("haven't implemented deletes over HTTP yet"))
params := map[string]string{}
for key := range req.URL.Query() {
params[key] = req.FormValue(key)
}
if err := r.RemoveDatasetRef(req.Context(), params); err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}

w.WriteHeader(http.StatusOK)
return
default:
w.WriteHeader(http.StatusNotFound)
Expand Down

0 comments on commit e2a6d3a

Please sign in to comment.