fix: filestore silently being skipped on add if it wasn't enabled
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
Mar 6, 2017 at 19:16 UTC
ffeef8c9cb7bb0e177e8d679833f118e82aa4064
2 files changed
+24
-5
core/commands/add.go
+16
-3
@@ -1,23 +1,24 @@
1
package commands
2
3
import (
4
+ "errors"
5
"fmt"
6
"io"
7
7
- "github.com/ipfs/go-ipfs/core/coreunix"
8
- "gx/ipfs/QmeWjRodbcZFKe5tMN7poEx3izym6osrLSnTLf9UjJZBbs/pb"
9
-
8
bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
9
blockservice "github.com/ipfs/go-ipfs/blockservice"
10
cmds "github.com/ipfs/go-ipfs/commands"
11
files "github.com/ipfs/go-ipfs/commands/files"
12
core "github.com/ipfs/go-ipfs/core"
13
+ "github.com/ipfs/go-ipfs/core/coreunix"
14
offline "github.com/ipfs/go-ipfs/exchange/offline"
15
dag "github.com/ipfs/go-ipfs/merkledag"
16
dagtest "github.com/ipfs/go-ipfs/merkledag/test"
17
mfs "github.com/ipfs/go-ipfs/mfs"
18
ft "github.com/ipfs/go-ipfs/unixfs"
19
+
20
u "gx/ipfs/QmZuY8aV7zbNXVy6DyN9SmnuH3o9nG852F4aTiSBpts8d1/go-ipfs-util"
21
+ "gx/ipfs/QmeWjRodbcZFKe5tMN7poEx3izym6osrLSnTLf9UjJZBbs/pb"
22
)
23
24
// 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:
129
res.SetError(err, cmds.ErrNormal)
130
return
131
}
132
+
133
+ cfg, err := n.Repo.Config()
134
+ if err != nil {
135
+ res.SetError(err, cmds.ErrNormal)
136
+ return
137
+ }
138
// check if repo will exceed storage limit if added
139
// TODO: this doesn't handle the case if the hashed file is already in blocks (deduplicated)
140
// 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:
155
nocopy, _, _ := req.Option(noCopyOptionName).Bool()
156
fscache, _, _ := req.Option(fstoreCacheOptionName).Bool()
157
158
+ if nocopy && !cfg.Experimental.FilestoreEnabled {
159
+ res.SetError(errors.New("filestore is not enabled, see https://git.io/vy4XN"),
160
+ cmds.ErrClient)
161
+ return
162
+ }
163
+
164
if nocopy && !rbset {
165
rawblks = true
166
}
test/sharness/t0270-filestore.sh
+8
-2
@@ -24,7 +24,7 @@ assert_repo_size_less_than() {
24
25
test_expect_success "check repo size" '
26
test "$(get_repo_size)" -lt "$expval" ||
27
- (get_repo_size && false)
27
+ test_fsh get_repo_size
28
'
29
}
30
@@ -33,7 +33,7 @@ assert_repo_size_greater_than() {
33
34
test_expect_success "check repo size" '
35
test "$(get_repo_size)" -gt "$expval" ||
36
- (get_repo_size && false)
36
+ test_fsh get_repo_size
37
'
38
}
39
@@ -68,6 +68,12 @@ init_ipfs_filestore() {
68
69
test_init_ipfs
70
71
+ test_expect_success "nocopy add errors and has right message" '
72
+ test_must_fail ipfs add --nocopy -r somedir 2> add_out &&
73
+ grep "filestore is not enabled" add_out
74
+ '
75
+
76
+
77
test_expect_success "enable filestore config setting" '
78
ipfs config --json Experimental.FilestoreEnabled true
79
'