From d295f4ad2c4e539d1294ea2336916c2d8f6b35e6 Mon Sep 17 00:00:00 2001 From: gammazero <11790789+gammazero@users.noreply.github.com> Date: Thu, 15 Aug 2024 10:55:50 -0700 Subject: [PATCH] Fix path parsing --- main.go | 23 +++++++++++------------ sharness/t0010-local-node.sh | 6 +++--- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index d1553d2..ae85a59 100644 --- a/main.go +++ b/main.go @@ -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. diff --git a/sharness/t0010-local-node.sh b/sharness/t0010-local-node.sh index a8b31d1..9276b57 100755 --- a/sharness/t0010-local-node.sh +++ b/sharness/t0010-local-node.sh @@ -15,12 +15,12 @@ test_expect_success "create a test file" ' cat hash ' test_expect_success "retrieve a single file" ' - ipget --node=local "/ipfs/$(