diff --git a/core/commands/add.go b/core/commands/add.go index e9e3bd87d..3c2e9a074 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -1,23 +1,24 @@ package commands import ( + "errors" "fmt" "io" - "github.com/ipfs/go-ipfs/core/coreunix" - "gx/ipfs/QmeWjRodbcZFKe5tMN7poEx3izym6osrLSnTLf9UjJZBbs/pb" - bstore "github.com/ipfs/go-ipfs/blocks/blockstore" blockservice "github.com/ipfs/go-ipfs/blockservice" cmds "github.com/ipfs/go-ipfs/commands" files "github.com/ipfs/go-ipfs/commands/files" core "github.com/ipfs/go-ipfs/core" + "github.com/ipfs/go-ipfs/core/coreunix" offline "github.com/ipfs/go-ipfs/exchange/offline" dag "github.com/ipfs/go-ipfs/merkledag" dagtest "github.com/ipfs/go-ipfs/merkledag/test" mfs "github.com/ipfs/go-ipfs/mfs" ft "github.com/ipfs/go-ipfs/unixfs" + u "gx/ipfs/QmZuY8aV7zbNXVy6DyN9SmnuH3o9nG852F4aTiSBpts8d1/go-ipfs-util" + "gx/ipfs/QmeWjRodbcZFKe5tMN7poEx3izym6osrLSnTLf9UjJZBbs/pb" ) // Error indicating the max depth has been exceded. @@ -128,6 +129,12 @@ You can now refer to the added file in a gateway, like so: res.SetError(err, cmds.ErrNormal) return } + + cfg, err := n.Repo.Config() + if err != nil { + res.SetError(err, cmds.ErrNormal) + return + } // check if repo will exceed storage limit if added // TODO: this doesn't handle the case if the hashed file is already in blocks (deduplicated) // TODO: conditional GC is disabled due to it is somehow not possible to pass the size to the daemon @@ -148,6 +155,12 @@ You can now refer to the added file in a gateway, like so: nocopy, _, _ := req.Option(noCopyOptionName).Bool() fscache, _, _ := req.Option(fstoreCacheOptionName).Bool() + if nocopy && !cfg.Experimental.FilestoreEnabled { + res.SetError(errors.New("filestore is not enabled, see https://git.io/vy4XN"), + cmds.ErrClient) + return + } + if nocopy && !rbset { rawblks = true } diff --git a/test/sharness/t0270-filestore.sh b/test/sharness/t0270-filestore.sh index 7ccf7fd7e..c6dff3077 100755 --- a/test/sharness/t0270-filestore.sh +++ b/test/sharness/t0270-filestore.sh @@ -24,7 +24,7 @@ assert_repo_size_less_than() { test_expect_success "check repo size" ' test "$(get_repo_size)" -lt "$expval" || - (get_repo_size && false) + test_fsh get_repo_size ' } @@ -33,7 +33,7 @@ assert_repo_size_greater_than() { test_expect_success "check repo size" ' test "$(get_repo_size)" -gt "$expval" || - (get_repo_size && false) + test_fsh get_repo_size ' } @@ -68,6 +68,12 @@ init_ipfs_filestore() { test_init_ipfs + test_expect_success "nocopy add errors and has right message" ' + test_must_fail ipfs add --nocopy -r somedir 2> add_out && + grep "filestore is not enabled" add_out + ' + + test_expect_success "enable filestore config setting" ' ipfs config --json Experimental.FilestoreEnabled true '