Skip to content

Commit

Permalink
Merge pull request #3749 from ipfs/fix/filestore/enabled-check
Browse files Browse the repository at this point in the history
fix: filestore silently being skipped on add if it wasn't enabled
  • Loading branch information
whyrusleeping authored Mar 6, 2017
2 parents 7c707b0 + ffeef8c commit 459cead
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
19 changes: 16 additions & 3 deletions core/commands/add.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
10 changes: 8 additions & 2 deletions test/sharness/t0270-filestore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
'
}

Expand All @@ -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
'
}

Expand Down Expand Up @@ -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
'
Expand Down

0 comments on commit 459cead

Please sign in to comment.