Skip to content

Commit

Permalink
Address c.r. and additional tweaks.
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
  • Loading branch information
kevina committed Jul 13, 2018
1 parent 8dd970b commit 1f29699
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
7 changes: 6 additions & 1 deletion core/commands/urlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var urlStoreCmd = &cmds.Command{

var urlAdd = &cmds.Command{
Helptext: cmdkit.HelpText{
Tagline: "Add URLs via urlstore.",
Tagline: "Add URL via urlstore.",
LongDescription: `
Add URLs to ipfs without storing the data locally.
Expand Down Expand Up @@ -57,6 +57,11 @@ time.
return
}

if !filestore.IsURL(url) {
res.SetError(fmt.Errorf("unsupported url syntax: %s", url), cmdkit.ErrNormal)
return
}

cfg, err := n.Repo.Config()
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
Expand Down
2 changes: 1 addition & 1 deletion filestore/filestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func TestIsURL(t *testing.T) {
if !IsURL("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")
}
}
3 changes: 2 additions & 1 deletion filestore/fsrefstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ func (f *FileManager) PutMany(bs []*posinfo.FilestoreNode) error {
}

// 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 {
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] == '/') ||
Expand Down
5 changes: 4 additions & 1 deletion importer/helpers/dagbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ type DagBuilderParams struct {
// filestore adds
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
}

Expand All @@ -68,7 +71,7 @@ func (dbp *DagBuilderParams) New(spl chunker.Splitter) *DagBuilderHelper {
db.stat = fi.Stat()
}

if dbp.URL != "" {
if dbp.URL != "" && dbp.NoCopy {
db.fullPath = dbp.URL
}
return db
Expand Down

0 comments on commit 1f29699

Please sign in to comment.