@cryptotaxi247 / kubo / commits / 1f29699d9

Address c.r. and additional tweaks.

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed Jun 29, 2018 at 23:03 UTC 1f29699d90a595b861ffacd5795ad15133d6dab6
4 files changed +13 -4
core/commands/urlstore.go
+6 -1
@@ -26,7 +26,7 @@ var urlStoreCmd = &cmds.Command{
26
27 var urlAdd = &cmds.Command{
28 Helptext: cmdkit.HelpText{
29 - Tagline: "Add URLs via urlstore.",
29 + Tagline: "Add URL via urlstore.",
30 LongDescription: `
31 Add URLs to ipfs without storing the data locally.
32
@@ -57,6 +57,11 @@ time.
57 return
58 }
59
60 + if !filestore.IsURL(url) {
61 + res.SetError(fmt.Errorf("unsupported url syntax: %s", url), cmdkit.ErrNormal)
62 + return
63 + }
64 +
65 cfg, err := n.Repo.Config()
66 if err != nil {
67 res.SetError(err, cmdkit.ErrNormal)
filestore/filestore_test.go
+1 -1
@@ -171,7 +171,7 @@ func TestIsURL(t *testing.T) {
171 if !IsURL("https://www.example.com") {
172 t.Fatal("IsURL failed: https://www.example.com")
173 }
174 - if IsURL("adir/afile") {
174 + if IsURL("adir/afile") || IsURL("http:/ /afile") || IsURL("http:/a/file") {
175 t.Fatal("IsURL recognized non-url")
176 }
177 }
filestore/fsrefstore.go
+2 -1
@@ -314,7 +314,8 @@ func (f *FileManager) PutMany(bs []*posinfo.FilestoreNode) error {
314 }
315
316 // IsURL returns true if the string represents a valid URL that the
317 -// urlstore can handle.
317 +// urlstore can handle. More specifically it returns true if a string
318 +// begins with 'http://' or 'https://'.
319 func IsURL(str string) bool {
320 return (len(str) > 7 && str[0] == 'h' && str[1] == 't' && str[2] == 't' && str[3] == 'p') &&
321 ((len(str) > 8 && str[4] == 's' && str[5] == ':' && str[6] == '/' && str[7] == '/') ||
importer/helpers/dagbuilder.go
+4 -1
@@ -49,6 +49,9 @@ type DagBuilderParams struct {
49 // filestore adds
50 NoCopy bool
51
52 + // URL if non-empty (and NoCopy is also true) indicates that the
53 + // file will not be stored in the datastore but instead retrieved
54 + // from this location via the urlstore.
55 URL string
56 }
57
@@ -68,7 +71,7 @@ func (dbp *DagBuilderParams) New(spl chunker.Splitter) *DagBuilderHelper {
71 db.stat = fi.Stat()
72 }
73
71 - if dbp.URL != "" {
74 + if dbp.URL != "" && dbp.NoCopy {
75 db.fullPath = dbp.URL
76 }
77 return db