Skip to content

Commit

Permalink
Add "--inline" option to add, Use 64 as the default id-hash limit.
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
  • Loading branch information
kevina committed Apr 16, 2018
1 parent bb4a520 commit f0a4f29
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
cidVersionOptionName = "cid-version"
hashOptionName = "hash"
idHashLimitOptionName = "id-hash-limit"
inlineOptionName = "inline"
)

const adderOutChanSize = 8
Expand Down Expand Up @@ -121,7 +122,8 @@ You can now check what blocks have been created by:
cmdkit.BoolOption(fstoreCacheOptionName, "Check the filestore for pre-existing blocks. (experimental)"),
cmdkit.IntOption(cidVersionOptionName, "CID version. Defaults to 0 unless an option that depends on CIDv1 is passed. (experimental)"),
cmdkit.StringOption(hashOptionName, "Hash function to use. Implies CIDv1 if not sha2-256. (experimental)").WithDefault("sha2-256"),
cmdkit.IntOption(idHashLimitOptionName, "Id hash maxium size. -1 disables. (experimental)").WithDefault(-1),
cmdkit.BoolOption(inlineOptionName, "Inline small objects using identity hash. (experimental)"),
cmdkit.IntOption(idHashLimitOptionName, "Identity hash maxium size. (experimental)").WithDefault(64),
},
PreRun: func(req *cmds.Request, env cmds.Environment) error {
quiet, _ := req.Options[quietOptionName].(bool)
Expand Down Expand Up @@ -175,6 +177,7 @@ You can now check what blocks have been created by:
fscache, _ := req.Options[fstoreCacheOptionName].(bool)
cidVer, cidVerSet := req.Options[cidVersionOptionName].(int)
hashFunStr, _ := req.Options[hashOptionName].(string)
inline, _ := req.Options[inlineOptionName].(bool)
idHashLimit, _ := req.Options[idHashLimitOptionName].(int)

// The arguments are subject to the following constraints.
Expand Down Expand Up @@ -285,10 +288,12 @@ You can now check what blocks have been created by:
fileAdder.NoCopy = nocopy
fileAdder.CidOpts = &cide.Opts{Prefix: prefix}

err = fileAdder.CidOpts.SetIdHashLimit(idHashLimit)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
if inline {
err = fileAdder.CidOpts.SetIdHashLimit(idHashLimit)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
}
}

if hash {
Expand Down
2 changes: 1 addition & 1 deletion test/sharness/t0040-add-and-cat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ test_add_cat_expensive "--cid-version=1" "zdj7WcatQrtuE4WMkS4XsfsMixuQN2po4irkYh
# encoded with the blake2b-256 hash funtion
test_add_cat_expensive '--hash=blake2b-256' "zDMZof1kwndounDzQCANUHjiE3zt1mPEgx7RE3JTHoZrRRa79xcv"

test_add_named_pipe " Post http://$API_ADDR/api/v0/add?chunker=size-262144&encoding=json&hash=sha2-256&id-hash-limit=-1&pin=true&progress=true&recursive=true&stream-channels=true:"
test_add_named_pipe " Post http://$API_ADDR/api/v0/add?chunker=size-262144&encoding=json&hash=sha2-256&id-hash-limit=64&pin=true&progress=true&recursive=true&stream-channels=true:"

test_add_pwd_is_symlink

Expand Down

0 comments on commit f0a4f29

Please sign in to comment.