filestore: Return consistent err msg. when file/urlstore is not enabled.
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
Kevin Atkinson committed
Jun 26, 2018 at 22:30 UTC
8dd970b73aa48af72c85185d3f9edbaac2dd081e
5 files changed
+13
-8
core/commands/add.go
+2
-2
@@ -10,6 +10,7 @@ import (
10
blockservice "github.com/ipfs/go-ipfs/blockservice"
11
core "github.com/ipfs/go-ipfs/core"
12
"github.com/ipfs/go-ipfs/core/coreunix"
13
+ filestore "github.com/ipfs/go-ipfs/filestore"
14
dag "github.com/ipfs/go-ipfs/merkledag"
15
dagtest "github.com/ipfs/go-ipfs/merkledag/test"
16
mfs "github.com/ipfs/go-ipfs/mfs"
@@ -183,8 +184,7 @@ You can now check what blocks have been created by:
184
185
// nocopy -> filestoreEnabled
186
if nocopy && !cfg.Experimental.FilestoreEnabled {
186
- res.SetError(errors.New("filestore is not enabled, see https://git.io/vNItf"),
187
- cmdkit.ErrClient)
187
+ res.SetError(filestore.ErrFilestoreNotEnabled, cmdkit.ErrClient)
188
return
189
}
190
core/commands/filestore.go
+1
-1
@@ -237,7 +237,7 @@ func getFilestore(env interface{}) (*core.IpfsNode, *filestore.Filestore, error)
237
}
238
fs := n.Filestore
239
if fs == nil {
240
- return n, nil, fmt.Errorf("filestore not enabled")
240
+ return n, nil, filestore.ErrFilestoreNotEnabled
241
}
242
return n, fs, err
243
}
core/commands/urlstore.go
+2
-1
@@ -7,6 +7,7 @@ import (
7
"strings"
8
9
cmds "github.com/ipfs/go-ipfs/commands"
10
+ filestore "github.com/ipfs/go-ipfs/filestore"
11
balanced "github.com/ipfs/go-ipfs/importer/balanced"
12
ihelper "github.com/ipfs/go-ipfs/importer/helpers"
13
@@ -63,7 +64,7 @@ time.
64
}
65
66
if !cfg.Experimental.UrlstoreEnabled {
66
- res.SetError(fmt.Errorf("URL store not enabled."), cmdkit.ErrNormal)
67
+ res.SetError(filestore.ErrUrlstoreNotEnabled, cmdkit.ErrNormal)
68
return
69
}
70
filestore/filestore.go
+4
@@ -9,6 +9,7 @@ package filestore
9
10
import (
11
"context"
12
+ "errors"
13
14
blocks "gx/ipfs/QmTRCUvZLiir12Qr6MV3HKfKMHX8Nf1Vddn6t2g5nsQSb9/go-block-format"
15
posinfo "gx/ipfs/QmUWsXLvYYDAaoAt9TPZpFX4ffHHMg46AHrz1ZLTN5ABbe/go-ipfs-posinfo"
@@ -20,6 +21,9 @@ import (
21
22
var log = logging.Logger("filestore")
23
24
+var ErrFilestoreNotEnabled = errors.New("filestore is not enabled, see https://git.io/vNItf")
25
+var ErrUrlstoreNotEnabled = errors.New("urlstore is not enabled")
26
+
27
// Filestore implements a Blockstore by combining a standard Blockstore
28
// to store regular blocks and a special Blockstore called
29
// FileManager to store blocks which data exists in an external file.
filestore/fsrefstore.go
+4
-4
@@ -159,7 +159,7 @@ func unmarshalDataObj(o interface{}) (*pb.DataObj, error) {
159
160
func (f *FileManager) readFileDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) {
161
if !f.AllowFiles {
162
- return nil, fmt.Errorf("filestore not enabled")
162
+ return nil, ErrFilestoreNotEnabled
163
}
164
165
p := filepath.FromSlash(d.GetFilePath())
@@ -202,7 +202,7 @@ func (f *FileManager) readFileDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error)
202
// reads and verifies the block from URL
203
func (f *FileManager) readURLDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) {
204
if !f.AllowUrls {
205
- return nil, fmt.Errorf("urlstore not enabled")
205
+ return nil, ErrUrlstoreNotEnabled
206
}
207
208
req, err := http.NewRequest("GET", d.GetFilePath(), nil)
@@ -267,12 +267,12 @@ func (f *FileManager) putTo(b *posinfo.FilestoreNode, to putter) error {
267
268
if IsURL(b.PosInfo.FullPath) {
269
if !f.AllowUrls {
270
- return fmt.Errorf("urlstore not enabled")
270
+ return ErrUrlstoreNotEnabled
271
}
272
dobj.FilePath = proto.String(b.PosInfo.FullPath)
273
} else {
274
if !f.AllowFiles {
275
- return fmt.Errorf("filestore not enabled")
275
+ return ErrFilestoreNotEnabled
276
}
277
if !filepath.HasPrefix(b.PosInfo.FullPath, f.root) {
278
return fmt.Errorf("cannot add filestore references outside ipfs root (%s)", f.root)