Commit 1f29699d authored by Kevin Atkinson's avatar Kevin Atkinson

Address c.r. and additional tweaks.

License: MIT
Signed-off-by: default avatarKevin Atkinson <k@kevina.org>
parent 8dd970b7
...@@ -26,7 +26,7 @@ var urlStoreCmd = &cmds.Command{ ...@@ -26,7 +26,7 @@ var urlStoreCmd = &cmds.Command{
var urlAdd = &cmds.Command{ var urlAdd = &cmds.Command{
Helptext: cmdkit.HelpText{ Helptext: cmdkit.HelpText{
Tagline: "Add URLs via urlstore.", Tagline: "Add URL via urlstore.",
LongDescription: ` LongDescription: `
Add URLs to ipfs without storing the data locally. Add URLs to ipfs without storing the data locally.
...@@ -57,6 +57,11 @@ time. ...@@ -57,6 +57,11 @@ time.
return return
} }
if !filestore.IsURL(url) {
res.SetError(fmt.Errorf("unsupported url syntax: %s", url), cmdkit.ErrNormal)
return
}
cfg, err := n.Repo.Config() cfg, err := n.Repo.Config()
if err != nil { if err != nil {
res.SetError(err, cmdkit.ErrNormal) res.SetError(err, cmdkit.ErrNormal)
......
...@@ -171,7 +171,7 @@ func TestIsURL(t *testing.T) { ...@@ -171,7 +171,7 @@ func TestIsURL(t *testing.T) {
if !IsURL("https://www.example.com") { if !IsURL("https://www.example.com") {
t.Fatal("IsURL failed: https://www.example.com") t.Fatal("IsURL failed: https://www.example.com")
} }
if IsURL("adir/afile") { if IsURL("adir/afile") || IsURL("http:/ /afile") || IsURL("http:/a/file") {
t.Fatal("IsURL recognized non-url") t.Fatal("IsURL recognized non-url")
} }
} }
...@@ -314,7 +314,8 @@ func (f *FileManager) PutMany(bs []*posinfo.FilestoreNode) error { ...@@ -314,7 +314,8 @@ func (f *FileManager) PutMany(bs []*posinfo.FilestoreNode) error {
} }
// IsURL returns true if the string represents a valid URL that the // IsURL returns true if the string represents a valid URL that the
// urlstore can handle. // urlstore can handle. More specifically it returns true if a string
// begins with 'http://' or 'https://'.
func IsURL(str string) bool { func IsURL(str string) bool {
return (len(str) > 7 && str[0] == 'h' && str[1] == 't' && str[2] == 't' && str[3] == 'p') && return (len(str) > 7 && str[0] == 'h' && str[1] == 't' && str[2] == 't' && str[3] == 'p') &&
((len(str) > 8 && str[4] == 's' && str[5] == ':' && str[6] == '/' && str[7] == '/') || ((len(str) > 8 && str[4] == 's' && str[5] == ':' && str[6] == '/' && str[7] == '/') ||
......
...@@ -49,6 +49,9 @@ type DagBuilderParams struct { ...@@ -49,6 +49,9 @@ type DagBuilderParams struct {
// filestore adds // filestore adds
NoCopy bool NoCopy bool
// URL if non-empty (and NoCopy is also true) indicates that the
// file will not be stored in the datastore but instead retrieved
// from this location via the urlstore.
URL string URL string
} }
...@@ -68,7 +71,7 @@ func (dbp *DagBuilderParams) New(spl chunker.Splitter) *DagBuilderHelper { ...@@ -68,7 +71,7 @@ func (dbp *DagBuilderParams) New(spl chunker.Splitter) *DagBuilderHelper {
db.stat = fi.Stat() db.stat = fi.Stat()
} }
if dbp.URL != "" { if dbp.URL != "" && dbp.NoCopy {
db.fullPath = dbp.URL db.fullPath = dbp.URL
} }
return db return db
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment