提交 25a0db4f 作者: Steven Allen

add pinning support to the urlstore

fixes #5833

License: MIT
Signed-off-by: 's avatarSteven Allen <steven@stebalien.com>
上级 7956adad
......@@ -7,6 +7,7 @@ import (
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
filestore "github.com/ipfs/go-ipfs/filestore"
pin "github.com/ipfs/go-ipfs/pin"
chunk "gx/ipfs/QmR4QQVkBZsZENRjYFVi8dEtPL3daZRNKk24m4r6WKJHNm/go-ipfs-chunker"
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
......@@ -36,9 +37,6 @@ control.
The file is added using raw-leaves but otherwise using the default
settings for 'ipfs add'.
The file is not pinned, so this command should be followed by an 'ipfs
pin add'.
This command is considered temporary until a better solution can be
found. It may disappear or the semantics can change at any
time.
......@@ -46,6 +44,7 @@ time.
},
Options: []cmdkit.Option{
cmdkit.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."),
cmdkit.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true),
},
Arguments: []cmdkit.Argument{
cmdkit.StringArg("url", true, false, "URL to add to IPFS"),
......@@ -73,6 +72,7 @@ time.
}
useTrickledag, _ := req.Options[trickleOptionName].(bool)
dopin, _ := req.Options[pinOptionName].(bool)
hreq, err := http.NewRequest("GET", url, nil)
if err != nil {
......@@ -87,6 +87,11 @@ time.
return fmt.Errorf("expected code 200, got: %d", hres.StatusCode)
}
if dopin {
// Take the pinlock
defer n.Blockstore.PinLock().Unlock()
}
chk := chunk.NewSizeSplitter(hres.Body, chunk.DefaultBlockSize)
prefix := cid.NewPrefixV1(cid.DagProtobuf, mh.SHA2_256)
dbp := &ihelper.DagBuilderParams{
......@@ -102,13 +107,22 @@ time.
if useTrickledag {
layout = trickle.Layout
}
root, err := layout(dbp.New(chk))
if err != nil {
return err
}
c := root.Cid()
if dopin {
n.Pinning.PinWithMode(c, pin.Recursive)
if err := n.Pinning.Flush(); err != nil {
return err
}
}
return cmds.EmitOnce(res, &BlockStat{
Key: root.Cid().String(),
Key: c.String(),
Size: int(hres.ContentLength),
})
},
......
......@@ -46,9 +46,8 @@ test_expect_success "enable urlstore" '
test_launch_ipfs_daemon --offline
test_expect_success "add files using gateway address via url store" '
HASH1=$(ipfs urlstore add http://127.0.0.1:$GWAY_PORT/ipfs/$HASH1a) &&
HASH2=$(ipfs urlstore add http://127.0.0.1:$GWAY_PORT/ipfs/$HASH2a) &&
ipfs pin add $HASH1 $HASH2
HASH1=$(ipfs urlstore add --pin=false http://127.0.0.1:$GWAY_PORT/ipfs/$HASH1a) &&
HASH2=$(ipfs urlstore add http://127.0.0.1:$GWAY_PORT/ipfs/$HASH2a)
'
test_expect_success "make sure hashes are different" '
......@@ -99,7 +98,6 @@ test_expect_success "gatway no longer has files" '
cat <<EOF | sort > verify_expect_2
error zb2rhX1q5oFFzEkPNsTe1Y8osUdFqSQGjUWRZsqC9fbY6WVSk 262144 http://127.0.0.1:$GWAY_PORT/ipfs/QmUow2T4P69nEsqTQDZCt8yg9CPS8GFmpuDAr5YtsPhTdM 0
error zb2rhYbKFn1UWGHXaAitcdVTkDGTykX8RFpGWzRFuLpoe9VE4 237856 http://127.0.0.1:$GWAY_PORT/ipfs/QmUow2T4P69nEsqTQDZCt8yg9CPS8GFmpuDAr5YtsPhTdM 262144
error zb2rhjddJ5DNzBrFu8G6CP1ApY25BukwCeskXHzN1H18CiVVZ 2222 http://127.0.0.1:$GWAY_PORT/ipfs/QmcHm3BL2cXuQ6rJdKQgPrmT9suqGkfy2KzH3MkXPEBXU6 0
EOF
test_expect_success "ipfs filestore verify is correct" '
......@@ -113,7 +111,7 @@ test_expect_success "files can not be retrieved via the urlstore" '
'
test_expect_success "remove broken files" '
ipfs pin rm $HASH1 $HASH2 &&
ipfs pin rm $HASH2 &&
ipfs repo gc > /dev/null
'
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论