Skip to content

Commit

Permalink
Fix path parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero committed Aug 15, 2024
1 parent a6dab21 commit d295f4a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
23 changes: 11 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,24 @@ func parsePath(path string) (ipath.Path, error) {
if err == nil {
return ipfsPath, nil
}
origErr := err

ipfsPath, err = ipath.NewPath("/ipfs/" + path)
if err == nil {
return ipfsPath, nil
}

u, err := url.Parse(path)
if err != nil {
return nil, fmt.Errorf("%q could not be parsed: %s", path, err)
return nil, origErr
}

proto := u.Scheme
switch proto {
switch u.Scheme {
case "ipfs", "ipld", "ipns":
ipfsPath, err = ipath.NewPath(gopath.Join("/", proto, u.Host, u.Path))
return ipath.NewPath(gopath.Join("/", u.Scheme, u.Host, u.Path))
case "http", "https":
ipfsPath, err = ipath.NewPath(u.Path)
default:
return nil, fmt.Errorf("%q is not recognized as an IPFS path", path)
}
if err != nil {
return nil, fmt.Errorf("cannot create %s path: %w", proto, err)
return ipath.NewPath(u.Path)
}
return ipfsPath, nil
return nil, fmt.Errorf("%q is not recognized as an IPFS path", path)
}

// WriteTo writes the given node to the local filesystem at fpath.
Expand Down
6 changes: 3 additions & 3 deletions sharness/t0010-local-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ test_expect_success "create a test file" '
cat hash
'
test_expect_success "retrieve a single file" '
ipget --node=local "/ipfs/$(<hash)" &&
ipget --node=local "$(<hash)" &&
test_cmp test_file "$(<hash)"
'

test_expect_success "retrieve a single file with -o" '
ipget -o data.txt --node=local "/ipfs/$(<hash)" &&
ipget -o data.txt --node=local "$(<hash)" &&
test_cmp test_file "data.txt"
'

Expand All @@ -31,7 +31,7 @@ test_expect_success "create a test directory" '
'

test_expect_success "retrieve a directory" '
ipget --node=local -o got_dir "/ipfs/$(<dir_hash)" &&
ipget --node=local -o got_dir "$(<dir_hash)" &&
diff -ru test_dir got_dir
'

Expand Down

0 comments on commit d295f4a

Please sign in to comment.