Commit 360e8bbf authored by Łukasz Magiera's avatar Łukasz Magiera

Fix offline gateway directory logic

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent 89157f98
package iface package iface
import ( import (
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
ipfspath "gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path" ipfspath "gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path"
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
) )
//TODO: merge with ipfspath so we don't depend on it //TODO: merge with ipfspath so we don't depend on it
...@@ -106,6 +105,12 @@ type resolvedPath struct { ...@@ -106,6 +105,12 @@ type resolvedPath struct {
remainder string remainder string
} }
// Join appends provided segments to the base path
func Join(base Path, a ...string) Path {
s := ipfspath.Join(append([]string{base.String()}, a...))
return &path{path: ipfspath.FromString(s)}
}
// IpfsPath creates new /ipfs path from the provided CID // IpfsPath creates new /ipfs path from the provided CID
func IpfsPath(c cid.Cid) ResolvedPath { func IpfsPath(c cid.Cid) ResolvedPath {
return &resolvedPath{ return &resolvedPath{
......
...@@ -15,6 +15,7 @@ func (tp *provider) TestPath(t *testing.T) { ...@@ -15,6 +15,7 @@ func (tp *provider) TestPath(t *testing.T) {
t.Run("TestEmptyPathRemainder", tp.TestEmptyPathRemainder) t.Run("TestEmptyPathRemainder", tp.TestEmptyPathRemainder)
t.Run("TestInvalidPathRemainder", tp.TestInvalidPathRemainder) t.Run("TestInvalidPathRemainder", tp.TestInvalidPathRemainder)
t.Run("TestPathRoot", tp.TestPathRoot) t.Run("TestPathRoot", tp.TestPathRoot)
t.Run("TestPathJoin", tp.TestPathJoin)
} }
func (tp *provider) TestMutablePath(t *testing.T) { func (tp *provider) TestMutablePath(t *testing.T) {
...@@ -165,3 +166,14 @@ func (tp *provider) TestPathRoot(t *testing.T) { ...@@ -165,3 +166,14 @@ func (tp *provider) TestPathRoot(t *testing.T) {
t.Error("unexpected path cid") t.Error("unexpected path cid")
} }
} }
func (tp *provider) TestPathJoin(t *testing.T) {
p1, err := coreiface.ParsePath("/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz")
if err != nil {
t.Error(err)
}
if coreiface.Join(p1, "foo").String() != "/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz/foo" {
t.Error("unexpected path")
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment