diff --git a/actions/dataset.go b/actions/dataset.go index 3c9b5c8d0..1f5157ae4 100644 --- a/actions/dataset.go +++ b/actions/dataset.go @@ -3,6 +3,7 @@ package actions import ( "fmt" "os" + "strings" "github.com/ipfs/go-datastore" "github.com/qri-io/cafs" @@ -64,12 +65,22 @@ func SaveDataset(node *p2p.QriNode, dsp *dataset.DatasetPod, dryRun, pin bool) ( if ds.Transform != nil { mutateCheck := mutatedComponentsFunc(dsp) if ds.Transform.Script == nil { - var f *os.File - f, err = os.Open(ds.Transform.ScriptPath) - if err != nil { - return + if strings.HasPrefix(ds.Transform.ScriptPath, "/ipfs") || strings.HasPrefix(ds.Transform.ScriptPath, "/map") || strings.HasPrefix(ds.Transform.ScriptPath, "/cafs") { + var f cafs.File + f, err = node.Repo.Store().Get(datastore.NewKey(ds.Transform.ScriptPath)) + if err != nil { + return + } + ds.Transform.Script = f + } else { + var f *os.File + f, err = os.Open(ds.Transform.ScriptPath) + if err != nil { + return + } + ds.Transform.Script = f } - ds.Transform.Script = f + } // TODO - consider making this a standard method on dataset.Transform script := cafs.NewMemfileReader(ds.Transform.ScriptPath, ds.Transform.Script) diff --git a/actions/recall_test.go b/actions/recall_test.go new file mode 100644 index 000000000..356eab67f --- /dev/null +++ b/actions/recall_test.go @@ -0,0 +1,18 @@ +package actions + +import "testing" + +func TestRecall(t *testing.T) { + node := newTestNode(t) + ref := addNowTransformDataset(t, node) + + _, err := Recall(node, "", ref) + if err != nil { + t.Error(err) + } + + _, err = Recall(node, "tf", ref) + if err != nil { + t.Error(err) + } +} diff --git a/lib/datasets.go b/lib/datasets.go index 3f7d77811..00424228d 100644 --- a/lib/datasets.go +++ b/lib/datasets.go @@ -172,10 +172,8 @@ func (r *DatasetRequests) Save(p *SaveParams, res *repo.DatasetRef) (err error) } } - if p.ReturnBody { - if ref.Dataset != nil { - ref.Dataset.Body = body - } + if p.ReturnBody && ref.Dataset != nil { + ref.Dataset.Body = body } *res = ref @@ -196,6 +194,15 @@ type UpdateParams struct { // Update advances a dataset to the latest known version from either a peer or by // re-running a transform in the peer's namespace func (r *DatasetRequests) Update(p *UpdateParams, res *repo.DatasetRef) error { + if r.cli != nil { + if p.ReturnBody { + // can't send an io.Reader interface over RPC + p.ReturnBody = false + log.Error("cannot return body bytes over RPC, disabling body return") + } + return r.cli.Call("DatasetRequests.Update", p, res) + } + ref, err := repo.ParseDatasetRef(p.Ref) if err != nil { return err @@ -225,6 +232,9 @@ func (r *DatasetRequests) Update(p *UpdateParams, res *repo.DatasetRef) error { // SetPublishStatus updates the publicity of a reference in the peer's namespace func (r *DatasetRequests) SetPublishStatus(ref *repo.DatasetRef, res *bool) error { + if r.cli != nil { + return r.cli.Call("DatasetRequests.SetPublishStatus", ref, res) + } res = &ref.Published return actions.SetPublishStatus(r.node, ref, ref.Published) } diff --git a/lib/datasets_test.go b/lib/datasets_test.go index 0146d6736..4436b2d81 100644 --- a/lib/datasets_test.go +++ b/lib/datasets_test.go @@ -136,6 +136,47 @@ func TestDatasetRequestsSave(t *testing.T) { } } +func TestDatasetRequestsSaveRecall(t *testing.T) { + node := newTestQriNode(t) + ref := addNowTransformDataset(t, node) + r := NewDatasetRequests(node, nil) + + res := &repo.DatasetRef{} + err := r.Save(&SaveParams{Dataset: &dataset.DatasetPod{ + Peername: ref.Peername, + Name: ref.Name, + Meta: &dataset.Meta{Title: "an updated title"}, + }, ReturnBody: true}, res) + if err != nil { + t.Error("save failed") + } + + err = r.Save(&SaveParams{ + Dataset: &dataset.DatasetPod{ + Peername: ref.Peername, + Name: ref.Name, + Meta: &dataset.Meta{Title: "an updated title"}, + }, + Recall: "wut"}, res) + if err == nil { + t.Error("expected bad recall to error") + } + + err = r.Save(&SaveParams{ + Dataset: &dataset.DatasetPod{ + Peername: ref.Peername, + Name: ref.Name, + Meta: &dataset.Meta{Title: "new title!"}, + }, + Recall: "tf"}, res) + if err != nil { + t.Error(err) + } + if res.Dataset.Transform == nil { + t.Error("expected transform to exist on recalled save") + } +} + func TestDatasetRequestsSaveZip(t *testing.T) { rc, _ := regmock.NewMockServer() mr, err := testrepo.NewTestRepo(rc) diff --git a/lib/file.go b/lib/file.go index 205bef576..821e533ca 100644 --- a/lib/file.go +++ b/lib/file.go @@ -45,12 +45,12 @@ func AbsPath(path *string) (err error) { func pathKind(path string) string { if path == "" { return "none" - } - if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") { + } else if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") { return "http" - } - if strings.HasPrefix(path, "/ipfs") { + } else if strings.HasPrefix(path, "/ipfs") { return "ipfs" + } else if strings.HasPrefix(path, "/map") || strings.HasPrefix(path, "/cafs") { + return "cafs" } return "file" }