Fix offline gateway directory logic

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>


This commit was moved from ipfs/interface-go-ipfs-core@360e8bbf0b

This commit was moved from ipfs/boxo@aecc5aa1ac
This commit is contained in:
Łukasz Magiera 2019-01-04 02:35:40 +01:00
parent f012ef096a
commit 80aace0fa2
2 changed files with 19 additions and 2 deletions

View File

@ -1,9 +1,8 @@
package iface
import (
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
ipfspath "gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path"
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
)
//TODO: merge with ipfspath so we don't depend on it
@ -106,6 +105,12 @@ type resolvedPath struct {
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
func IpfsPath(c cid.Cid) ResolvedPath {
return &resolvedPath{

View File

@ -15,6 +15,7 @@ func (tp *provider) TestPath(t *testing.T) {
t.Run("TestEmptyPathRemainder", tp.TestEmptyPathRemainder)
t.Run("TestInvalidPathRemainder", tp.TestInvalidPathRemainder)
t.Run("TestPathRoot", tp.TestPathRoot)
t.Run("TestPathJoin", tp.TestPathJoin)
}
func (tp *provider) TestMutablePath(t *testing.T) {
@ -165,3 +166,14 @@ func (tp *provider) TestPathRoot(t *testing.T) {
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")
}
}