mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-25 04:17:44 +08:00
Merge pull request #8439 from ipfs/feat/change-dag-put-flag-names
change names of ipfs dag put flags to make changes clearer
This commit is contained in:
commit
ea45dc816d
@ -84,8 +84,8 @@ into an object of the specified format.
|
||||
cmds.FileArg("object data", true, true, "The object to put").EnableStdin(),
|
||||
},
|
||||
Options: []cmds.Option{
|
||||
cmds.StringOption("format", "f", "Format that the object will be added as.").WithDefault("dag-cbor"),
|
||||
cmds.StringOption("input-enc", "Format that the input object will be.").WithDefault("dag-json"),
|
||||
cmds.StringOption("store-codec", "Codec that the stored object will be encoded with").WithDefault("dag-cbor"),
|
||||
cmds.StringOption("input-codec", "Codec that the input object is encoded in").WithDefault("dag-json"),
|
||||
cmds.BoolOption("pin", "Pin this object when adding."),
|
||||
cmds.StringOption("hash", "Hash function to use").WithDefault("sha2-256"),
|
||||
},
|
||||
|
||||
@ -31,17 +31,17 @@ func dagPut(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e
|
||||
return err
|
||||
}
|
||||
|
||||
ienc, _ := req.Options["input-enc"].(string)
|
||||
format, _ := req.Options["format"].(string)
|
||||
inputCodec, _ := req.Options["input-codec"].(string)
|
||||
storeCodec, _ := req.Options["store-codec"].(string)
|
||||
hash, _ := req.Options["hash"].(string)
|
||||
dopin, _ := req.Options["pin"].(bool)
|
||||
|
||||
var icodec mc.Code
|
||||
if err := icodec.Set(ienc); err != nil {
|
||||
if err := icodec.Set(inputCodec); err != nil {
|
||||
return err
|
||||
}
|
||||
var fcodec mc.Code
|
||||
if err := fcodec.Set(format); err != nil {
|
||||
var scodec mc.Code
|
||||
if err := scodec.Set(storeCodec); err != nil {
|
||||
return err
|
||||
}
|
||||
var mhType mc.Code
|
||||
@ -51,7 +51,7 @@ func dagPut(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e
|
||||
|
||||
cidPrefix := cid.Prefix{
|
||||
Version: 1,
|
||||
Codec: uint64(fcodec),
|
||||
Codec: uint64(scodec),
|
||||
MhType: uint64(mhType),
|
||||
MhLength: -1,
|
||||
}
|
||||
@ -60,7 +60,7 @@ func dagPut(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
encoder, err := multicodec.LookupEncoder(uint64(fcodec))
|
||||
encoder, err := multicodec.LookupEncoder(uint64(scodec))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ test_dag_cmd() {
|
||||
'
|
||||
|
||||
test_expect_success "can add an ipld object using dag-json to dag-json" '
|
||||
IPLDHASH=$(cat ipld_object | ipfs dag put --input-enc=dag-json -f dag-json)
|
||||
IPLDHASH=$(cat ipld_object | ipfs dag put --input-codec dag-json --store-codec dag-json)
|
||||
'
|
||||
|
||||
test_expect_success "CID looks correct" '
|
||||
@ -54,7 +54,7 @@ test_dag_cmd() {
|
||||
'
|
||||
|
||||
test_expect_success "can add an ipld object using dag-json to dag-cbor" '
|
||||
IPLDHASH=$(cat ipld_object | ipfs dag put --input-enc=dag-json -f dag-cbor)
|
||||
IPLDHASH=$(cat ipld_object | ipfs dag put --input-codec dag-json --store-codec dag-cbor)
|
||||
'
|
||||
|
||||
test_expect_success "CID looks correct" '
|
||||
@ -75,7 +75,7 @@ test_dag_cmd() {
|
||||
# (1) dag-cbor input
|
||||
|
||||
test_expect_success "can add a dag-cbor input block stored as dag-cbor" '
|
||||
IPLDCBORHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-enc=dag-cbor -f dag-cbor)
|
||||
IPLDCBORHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-codec dag-cbor --store-codec dag-cbor)
|
||||
'
|
||||
|
||||
test_expect_success "dag-cbor CID looks correct" '
|
||||
@ -84,7 +84,7 @@ test_dag_cmd() {
|
||||
'
|
||||
|
||||
test_expect_success "can add a dag-cbor input block stored as dag-pb" '
|
||||
IPLDPBHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-enc=dag-cbor -f dag-pb)
|
||||
IPLDPBHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-codec dag-cbor --store-codec dag-pb)
|
||||
'
|
||||
|
||||
test_expect_success "dag-pb CID looks correct" '
|
||||
@ -93,7 +93,7 @@ test_dag_cmd() {
|
||||
'
|
||||
|
||||
test_expect_success "can add a dag-cbor input block stored as dag-json" '
|
||||
IPLDJSONHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-enc=dag-cbor -f dag-json)
|
||||
IPLDJSONHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-codec dag-cbor --store-codec dag-json)
|
||||
'
|
||||
|
||||
test_expect_success "dag-json CID looks correct" '
|
||||
@ -104,7 +104,7 @@ test_dag_cmd() {
|
||||
# (2) dag-json input
|
||||
|
||||
test_expect_success "can add a dag-json input block stored as dag-cbor" '
|
||||
IPLDCBORHASH=$(cat ipld_object_dagjson | ipfs dag put --input-enc=dag-json -f dag-cbor)
|
||||
IPLDCBORHASH=$(cat ipld_object_dagjson | ipfs dag put --input-codec dag-json --store-codec dag-cbor)
|
||||
'
|
||||
|
||||
test_expect_success "dag-cbor CID looks correct" '
|
||||
@ -113,7 +113,7 @@ test_dag_cmd() {
|
||||
'
|
||||
|
||||
test_expect_success "can add a dag-json input block stored as dag-pb" '
|
||||
IPLDPBHASH=$(cat ipld_object_dagjson | ipfs dag put --input-enc=dag-json -f dag-pb)
|
||||
IPLDPBHASH=$(cat ipld_object_dagjson | ipfs dag put --input-codec dag-json --store-codec dag-pb)
|
||||
'
|
||||
|
||||
test_expect_success "dag-pb CID looks correct" '
|
||||
@ -122,7 +122,7 @@ test_dag_cmd() {
|
||||
'
|
||||
|
||||
test_expect_success "can add a dag-json input block stored as dag-json" '
|
||||
IPLDJSONHASH=$(cat ipld_object_dagjson | ipfs dag put --input-enc=dag-json -f dag-json)
|
||||
IPLDJSONHASH=$(cat ipld_object_dagjson | ipfs dag put --input-codec dag-json --store-codec dag-json)
|
||||
'
|
||||
|
||||
test_expect_success "dag-json CID looks correct" '
|
||||
@ -133,7 +133,7 @@ test_dag_cmd() {
|
||||
# (3) dag-pb input
|
||||
|
||||
test_expect_success "can add a dag-pb input block stored as dag-cbor" '
|
||||
IPLDCBORHASH=$(cat ipld_object_dagpb | ipfs dag put --input-enc=dag-pb -f dag-cbor)
|
||||
IPLDCBORHASH=$(cat ipld_object_dagpb | ipfs dag put --input-codec dag-pb --store-codec dag-cbor)
|
||||
'
|
||||
|
||||
test_expect_success "dag-cbor CID looks correct" '
|
||||
@ -142,7 +142,7 @@ test_dag_cmd() {
|
||||
'
|
||||
|
||||
test_expect_success "can add a dag-pb input block stored as dag-pb" '
|
||||
IPLDPBHASH=$(cat ipld_object_dagpb | ipfs dag put --input-enc=dag-pb -f dag-pb)
|
||||
IPLDPBHASH=$(cat ipld_object_dagpb | ipfs dag put --input-codec dag-pb --store-codec dag-pb)
|
||||
'
|
||||
|
||||
test_expect_success "dag-pb CID looks correct" '
|
||||
@ -151,7 +151,7 @@ test_dag_cmd() {
|
||||
'
|
||||
|
||||
test_expect_success "can add a dag-pb input block stored as dag-json" '
|
||||
IPLDJSONHASH=$(cat ipld_object_dagpb | ipfs dag put --input-enc=dag-pb -f dag-json)
|
||||
IPLDJSONHASH=$(cat ipld_object_dagpb | ipfs dag put --input-codec dag-pb --store-codec dag-json)
|
||||
'
|
||||
|
||||
test_expect_success "dag-json CID looks correct" '
|
||||
@ -245,7 +245,7 @@ test_dag_cmd() {
|
||||
'
|
||||
|
||||
test_expect_success "retrieved object hashes back correctly" '
|
||||
IPLDHASH2=$(cat ipld_obj_out | ipfs dag put --input-enc=dag-json -f dag-cbor) &&
|
||||
IPLDHASH2=$(cat ipld_obj_out | ipfs dag put --input-codec dag-json --store-codec dag-cbor) &&
|
||||
test "$IPLDHASH" = "$IPLDHASH2"
|
||||
'
|
||||
|
||||
@ -272,7 +272,7 @@ test_dag_cmd() {
|
||||
'
|
||||
|
||||
test_expect_success "non-canonical dag-cbor input is normalized" '
|
||||
HASH=$(cat ../t0053-dag-data/non-canon.cbor | ipfs dag put --format=dag-cbor --input-enc=dag-cbor) &&
|
||||
HASH=$(cat ../t0053-dag-data/non-canon.cbor | ipfs dag put --store-codec dag-cbor --input-codec dag-cbor) &&
|
||||
test $HASH = "bafyreiawx7ona7oa2ptcoh6vwq4q6bmd7x2ibtkykld327bgb7t73ayrqm" ||
|
||||
test_fsh echo $HASH
|
||||
'
|
||||
@ -283,7 +283,7 @@ test_dag_cmd() {
|
||||
'
|
||||
|
||||
test_expect_success "add an ipld with pin" '
|
||||
PINHASH=$(printf {\"foo\":\"bar\"} | ipfs dag put --input-enc=dag-json --pin=true)
|
||||
PINHASH=$(printf {\"foo\":\"bar\"} | ipfs dag put --input-codec dag-json --pin=true)
|
||||
'
|
||||
|
||||
test_expect_success "after gc, objects still accessible" '
|
||||
@ -307,7 +307,7 @@ test_dag_cmd() {
|
||||
|
||||
test_expect_success "dag put with json dag-pb works" '
|
||||
ipfs dag get $HASH > pbjson &&
|
||||
cat pbjson | ipfs dag put --format=dag-pb --input-enc=dag-json > dag_put_out
|
||||
cat pbjson | ipfs dag put --store-codec=dag-pb --input-codec=dag-json > dag_put_out
|
||||
'
|
||||
|
||||
test_expect_success "dag put with dag-pb works output looks good" '
|
||||
@ -317,7 +317,7 @@ test_dag_cmd() {
|
||||
|
||||
test_expect_success "dag put with raw dag-pb works" '
|
||||
ipfs block get $HASH > pbraw &&
|
||||
cat pbraw | ipfs dag put --format=dag-pb --input-enc=dag-pb > dag_put_out
|
||||
cat pbraw | ipfs dag put --store-codec=dag-pb --input-codec=dag-pb > dag_put_out
|
||||
'
|
||||
|
||||
test_expect_success "dag put with dag-pb works output looks good" '
|
||||
@ -327,7 +327,7 @@ test_dag_cmd() {
|
||||
|
||||
test_expect_success "dag put with raw node works" '
|
||||
echo "foo bar" > raw_node_in &&
|
||||
HASH=$(ipfs dag put --format=raw --input-enc=raw -- raw_node_in) &&
|
||||
HASH=$(ipfs dag put --store-codec=raw --input-codec=raw -- raw_node_in) &&
|
||||
ipfs block get "$HASH" > raw_node_out &&
|
||||
test_cmp raw_node_in raw_node_out'
|
||||
|
||||
|
||||
@ -14,8 +14,8 @@ test_expect_success 'create test JSON files' '
|
||||
'
|
||||
|
||||
test_expect_success 'puts as CBOR work' '
|
||||
GOT_HASH_WITHOUT_NEWLINE="$(cat without_newline.json | ipfs dag put -f dag-cbor)"
|
||||
GOT_HASH_WITH_NEWLINE="$(cat with_newline.json | ipfs dag put -f dag-cbor)"
|
||||
GOT_HASH_WITHOUT_NEWLINE="$(cat without_newline.json | ipfs dag put --store-codec dag-cbor)"
|
||||
GOT_HASH_WITH_NEWLINE="$(cat with_newline.json | ipfs dag put --store-codec dag-cbor)"
|
||||
'
|
||||
|
||||
test_expect_success 'put hashes with or without newline are equal' '
|
||||
|
||||
@ -17,7 +17,7 @@ test_expect_success "prepare test data" '
|
||||
|
||||
test_dag_git() {
|
||||
test_expect_success "add objects via dag put" '
|
||||
find objects -type f -exec ipfs dag put --format=git-raw --input-enc=0x300078 --hash=sha1 {} \; -exec echo -n \; > hashes
|
||||
find objects -type f -exec ipfs dag put --store-codec=git-raw --input-codec=0x300078 --hash=sha1 {} \; -exec echo -n \; > hashes
|
||||
'
|
||||
|
||||
test_expect_success "successfully get added objects" '
|
||||
|
||||
Loading…
Reference in New Issue
Block a user