-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Save): fix saving dataset with viz stored in cafs
I tried to update the cfl dataset, couldn't get it to work on account of the viz script trying to load from a filepath. This now seems like a set of consistent issues we should look into when working on the "file pattern refacter": * making sure we always load the right things from the right places * maintaining a consistent dataset state through the save process, with readers being loaded once, and that point in time forming an assumption other function calls can rely on
- Loading branch information
Showing
4 changed files
with
48 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,39 @@ | ||
package base | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
|
||
datastore "github.com/ipfs/go-datastore" | ||
"github.com/qri-io/cafs" | ||
"github.com/qri-io/dataset" | ||
"github.com/qri-io/qri/repo" | ||
) | ||
|
||
// PrepareViz loads vizualization bytes from a local filepath | ||
func prepareViz(ds *dataset.Dataset) (err error) { | ||
func prepareViz(r repo.Repo, ds *dataset.Dataset) (err error) { | ||
// remove any empty vizualizations | ||
if ds.Viz != nil && ds.Viz.IsEmpty() { | ||
ds.Viz = nil | ||
return nil | ||
} | ||
|
||
if ds.Viz != nil && ds.Viz.ScriptPath != "" { | ||
// create a reader of script bytes | ||
scriptdata, err := ioutil.ReadFile(ds.Viz.ScriptPath) | ||
if err != nil { | ||
return err | ||
if strings.HasPrefix(ds.Viz.ScriptPath, "/ipfs") || strings.HasPrefix(ds.Viz.ScriptPath, "/map") || strings.HasPrefix(ds.Viz.ScriptPath, "/cafs") { | ||
var f cafs.File | ||
f, err = r.Store().Get(datastore.NewKey(ds.Viz.ScriptPath)) | ||
if err != nil { | ||
return | ||
} | ||
ds.Viz.Script = f | ||
} else { | ||
var f *os.File | ||
f, err = os.Open(ds.Viz.ScriptPath) | ||
if err != nil { | ||
return | ||
} | ||
ds.Viz.Script = f | ||
} | ||
ds.Viz.Script = bytes.NewReader(scriptdata) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters