Skip to content

Commit

Permalink
fix(lib.AbsPath): allow directories named 'http' in filepaths
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 committed Nov 5, 2018
1 parent a4deba6 commit 684d3be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion actions/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ func DeleteDataset(node *p2p.QriNode, ref *repo.DatasetRef) (err error) {
return fmt.Errorf("given path does not equal most recent dataset path: cannot delete a specific save, can only delete entire dataset history. use `me/dataset_name` to delete entire dataset")
}

// TODO - this is causing bad things in our tests
// TODO - this is causing bad things in our tests. For some reason core repo explodes with nil
// references when this is on and go test ./... is run from $GOPATH/github.com/qri-io/qri
// let's upgrade IPFS to the latest version & try again
// log, err := base.DatasetLog(r, *ref, 10000, 0, false)
// if err != nil {
// return err
Expand Down
9 changes: 3 additions & 6 deletions lib/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"github.com/qri-io/dataset/dsutil"
)

// AbsPath adjusts the provdide string to a path lib functions can work with
// AbsPath adjusts the provided string to a path lib functions can work with
// because paths for Qri can come from the local filesystem, an http url, or
// the distributed web, Absolutizing is a little tricky
//
// If lib in put params call for a path, running it through AbsPath before
// If lib in put params call for a path, running input through AbsPath before
// calling a lib function should help reduce errors. calling AbsPath on empty
// string has no effect
func AbsPath(path *string) (err error) {
Expand All @@ -35,9 +35,6 @@ func AbsPath(path *string) (err error) {
}

// TODO - perform tilda (~) expansion
if _, err = os.Stat(p); os.IsNotExist(err) {
return fmt.Errorf(`open "%s": no such file or directory`, p)
}
if filepath.IsAbs(p) {
return
}
Expand All @@ -49,7 +46,7 @@ func pathKind(path string) string {
if path == "" {
return "none"
}
if strings.HasPrefix(path, "http") {
if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") {
return "http"
}
if strings.HasPrefix(path, "/ipfs") {
Expand Down
13 changes: 13 additions & 0 deletions lib/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,24 @@ func TestAbsPath(t *testing.T) {
t.Fatal(err)
}

pathAbs, err := filepath.Abs("relative/path/data.yaml")
if err != nil {
t.Fatal(err)
}

httpAbs, err := filepath.Abs("http_got/relative/dataset.yaml")
if err != nil {
t.Fatal(err)
}

cases := []struct {
in, out, err string
}{
{"", "", ""},
{"http://example.com/zipfile.zip", "http://example.com/zipfile.zip", ""},
{"https://example.com/zipfile.zip", "https://example.com/zipfile.zip", ""},
{"relative/path/data.yaml", pathAbs, ""},
{"http_got/relative/dataset.yaml", httpAbs, ""},
{"/ipfs", "/ipfs", ""},
{tmp, tmp, ""},
}
Expand Down

0 comments on commit 684d3be

Please sign in to comment.