Skip to content

Commit

Permalink
refactor: allow-big-block
Browse files Browse the repository at this point in the history
- renamed override flag to --allow-big-block
- separate tests for default and override behavior
  • Loading branch information
lidel committed Sep 27, 2021
1 parent 445b9d7 commit 5189eeb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
14 changes: 7 additions & 7 deletions core/commands/object/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (

"github.com/ipfs/go-cid"
cmds "github.com/ipfs/go-ipfs-cmds"
coreiface "github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
coreiface "github.com/ipfs/interface-go-ipfs-core"

"github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/interface-go-ipfs-core/path"
)

const (
// FIXME: Confirm if this is the right name.
forceBlockSize = "force-block-size"
softBlockLimit = 1024 * 1024 // https://github.com/ipfs/go-ipfs/issues/7421#issuecomment-910833499
allowBigBlock = "allow-big-block"
)

var ObjectPatchCmd = &cmds.Command{
Expand Down Expand Up @@ -49,7 +49,7 @@ For modern use cases, use MFS with 'files' commands: 'ipfs files --help'.
"set-data": patchSetDataCmd,
},
Options: []cmds.Option{
cmds.BoolOption(forceBlockSize, "Disable block size check and allow commands to produce any output size.").WithDefault(false),
cmds.BoolOption(allowBigBlock, "Disable block size check and allow creation of blocks bigger than 1MB. WARNING: such blocks won't be transferable over the standard bitswap.").WithDefault(false),
},
}

Expand Down Expand Up @@ -270,7 +270,7 @@ Use MFS and 'files' commands instead:
}

func checkBlockSize(req *cmds.Request, c cid.Cid, dagAPI coreiface.APIDagService) error {
allowAnyBlockSize, _ := req.Options[forceBlockSize].(bool)
allowAnyBlockSize, _ := req.Options[allowBigBlock].(bool)
if allowAnyBlockSize {
return nil
}
Expand All @@ -286,8 +286,8 @@ func checkBlockSize(req *cmds.Request, c cid.Cid, dagAPI coreiface.APIDagService
if err != nil {
return err
}
if modifiedNodeSize > 1024 * 1024 {
return fmt.Errorf("object API does not support HAMT-sharding. To create big directories, please use the files API (MFS)")
if modifiedNodeSize > softBlockLimit {
return fmt.Errorf("produced block is over 1MB, object API is deprecated and does not support HAMT-sharding: to create big directories, please use the files API (MFS)")
}
return nil
}
12 changes: 8 additions & 4 deletions test/sharness/t0051-object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,18 @@ test_object_cmd() {
DIR=$(ipfs object new unixfs-dir)
for i in {1..13}
do
DIR=$(ipfs object patch --force-block-size=false "$DIR" add-link "$DIR.jpg" "$DIR")
DIR=$(ipfs object patch "$DIR" add-link "$DIR.jpg" "$DIR")
done
# This one will fail as it goes over the BS limit of 1MB.
test_expect_code 1 ipfs object patch --force-block-size=false "$DIR" add-link "$DIR.jpg" "$DIR" >patch_out 2>&1
# Fail when new block goes over the BS limit of 1MB, but allow manual override
test_expect_code 1 ipfs object patch "$DIR" add-link "$DIR.jpg" "$DIR" >patch_out 2>&1
'

test_expect_success "ipfs object patch add-link output has the correct error" '
grep "Error: object API does not support HAMT-sharding. To create big directories, please use the files API (MFS)" patch_out
grep "produced block is over 1MB, object API is deprecated and does not support HAMT-sharding: to create big directories, please use the files API (MFS)" patch_out
'

test_expect_success "ipfs object patch --allow-big-block=true add-link works" '
test_expect_code 0 ipfs object patch --allow-big-block=true "$DIR" add-link "$DIR.jpg" "$DIR"
'

test_expect_success "'ipfs object new foo' shouldn't crash" '
Expand Down

0 comments on commit 5189eeb

Please sign in to comment.