Skip to content

Commit

Permalink
fix(remote): remove dataset
Browse files Browse the repository at this point in the history
First, this commit renames `RemoveDatasetRef` to `RemoveDataset`. It calls on `base.RemoveNVersionsFromStore` to remove the blocks from the filestore, and uses `repo.DeleteRef` to remove the dataset reference from the repo

`RemoveDataset` calls the `datasetRemovePreCheck` function, if it exists, before it removes the dataset and its history.

`RemoveDataset` calls the `datasetRemoved` function, if it exists, after it removes the datasets and its history
  • Loading branch information
ramfox committed Oct 24, 2019
1 parent 9029271 commit 3c38191
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
golog "github.com/ipfs/go-log"
"github.com/qri-io/dag"
"github.com/qri-io/dag/dsync"
"github.com/qri-io/qri/base"
"github.com/qri-io/qri/config"
"github.com/qri-io/qri/dsref"
"github.com/qri-io/qri/logbook/logsync"
Expand Down Expand Up @@ -156,14 +157,21 @@ func (r *Remote) ResolveHeadRef(ctx context.Context, peername, name string) (*re
return ref, err
}

// RemoveDatasetRef handles requests to remove a dataset
func (r *Remote) RemoveDatasetRef(ctx context.Context, params map[string]string) error {
// RemoveDataset handles requests to remove a dataset
func (r *Remote) RemoveDataset(ctx context.Context, params map[string]string) error {
pid, ref, err := r.pidAndRefFromMeta(params)
if err != nil {
return err
}
log.Debug("remove dataset ", ref)

// run pre check hook
if r.datasetRemovePreCheck != nil {
if err = r.datasetRemovePreCheck(ctx, pid, ref); err != nil {
return err
}
}

if err := repo.CanonicalizeDatasetRef(r.node.Repo, &ref); err != nil {
if err == repo.ErrNotFound {
err = nil
Expand All @@ -172,13 +180,23 @@ func (r *Remote) RemoveDatasetRef(ctx context.Context, params map[string]string)
}
}

// remove all the versions of this dataset from the store
if err := base.RemoveNVersionsFromStore(ctx, r.node.Repo, &ref, -1); err != nil {
return err
}

// remove the dataset reference from the repo
if err := r.node.Repo.DeleteRef(ref); err != nil {
return err
}

// run completed hook
if r.datasetRemoved != nil {
if err := r.datasetRemoved(ctx, pid, ref); err != nil {
return err
}
}

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

func (r *Remote) dsPushPreCheck(ctx context.Context, info dag.Info, meta map[string]string) error {
Expand Down Expand Up @@ -259,8 +277,8 @@ func (r *Remote) dsRemovePreCheck(ctx context.Context, info dag.Info, meta map[s
return err
}

if r.datasetRemoved != nil {
if err = r.datasetRemoved(ctx, pid, ref); err != nil {
if r.datasetRemovePreCheck != nil {
if err = r.datasetRemovePreCheck(ctx, pid, ref); err != nil {
return err
}
}
Expand Down Expand Up @@ -365,7 +383,7 @@ func (r *Remote) RefsHTTPHandler() http.HandlerFunc {
for key := range req.URL.Query() {
params[key] = req.FormValue(key)
}
if err := r.RemoveDatasetRef(req.Context(), params); err != nil {
if err := r.RemoveDataset(req.Context(), params); err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
Expand Down

0 comments on commit 3c38191

Please sign in to comment.