提交 8dd970b7 作者: Kevin Atkinson

filestore: Return consistent err msg. when file/urlstore is not enabled.

License: MIT
Signed-off-by: 's avatarKevin Atkinson <k@kevina.org>
上级 6a4b1262
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
blockservice "github.com/ipfs/go-ipfs/blockservice" blockservice "github.com/ipfs/go-ipfs/blockservice"
core "github.com/ipfs/go-ipfs/core" core "github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreunix" "github.com/ipfs/go-ipfs/core/coreunix"
filestore "github.com/ipfs/go-ipfs/filestore"
dag "github.com/ipfs/go-ipfs/merkledag" dag "github.com/ipfs/go-ipfs/merkledag"
dagtest "github.com/ipfs/go-ipfs/merkledag/test" dagtest "github.com/ipfs/go-ipfs/merkledag/test"
mfs "github.com/ipfs/go-ipfs/mfs" mfs "github.com/ipfs/go-ipfs/mfs"
...@@ -183,8 +184,7 @@ You can now check what blocks have been created by: ...@@ -183,8 +184,7 @@ You can now check what blocks have been created by:
// nocopy -> filestoreEnabled // nocopy -> filestoreEnabled
if nocopy && !cfg.Experimental.FilestoreEnabled { if nocopy && !cfg.Experimental.FilestoreEnabled {
res.SetError(errors.New("filestore is not enabled, see https://git.io/vNItf"), res.SetError(filestore.ErrFilestoreNotEnabled, cmdkit.ErrClient)
cmdkit.ErrClient)
return return
} }
......
...@@ -237,7 +237,7 @@ func getFilestore(env interface{}) (*core.IpfsNode, *filestore.Filestore, error) ...@@ -237,7 +237,7 @@ func getFilestore(env interface{}) (*core.IpfsNode, *filestore.Filestore, error)
} }
fs := n.Filestore fs := n.Filestore
if fs == nil { if fs == nil {
return n, nil, fmt.Errorf("filestore not enabled") return n, nil, filestore.ErrFilestoreNotEnabled
} }
return n, fs, err return n, fs, err
} }
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"strings" "strings"
cmds "github.com/ipfs/go-ipfs/commands" cmds "github.com/ipfs/go-ipfs/commands"
filestore "github.com/ipfs/go-ipfs/filestore"
balanced "github.com/ipfs/go-ipfs/importer/balanced" balanced "github.com/ipfs/go-ipfs/importer/balanced"
ihelper "github.com/ipfs/go-ipfs/importer/helpers" ihelper "github.com/ipfs/go-ipfs/importer/helpers"
...@@ -63,7 +64,7 @@ time. ...@@ -63,7 +64,7 @@ time.
} }
if !cfg.Experimental.UrlstoreEnabled { if !cfg.Experimental.UrlstoreEnabled {
res.SetError(fmt.Errorf("URL store not enabled."), cmdkit.ErrNormal) res.SetError(filestore.ErrUrlstoreNotEnabled, cmdkit.ErrNormal)
return return
} }
......
...@@ -9,6 +9,7 @@ package filestore ...@@ -9,6 +9,7 @@ package filestore
import ( import (
"context" "context"
"errors"
blocks "gx/ipfs/QmTRCUvZLiir12Qr6MV3HKfKMHX8Nf1Vddn6t2g5nsQSb9/go-block-format" blocks "gx/ipfs/QmTRCUvZLiir12Qr6MV3HKfKMHX8Nf1Vddn6t2g5nsQSb9/go-block-format"
posinfo "gx/ipfs/QmUWsXLvYYDAaoAt9TPZpFX4ffHHMg46AHrz1ZLTN5ABbe/go-ipfs-posinfo" posinfo "gx/ipfs/QmUWsXLvYYDAaoAt9TPZpFX4ffHHMg46AHrz1ZLTN5ABbe/go-ipfs-posinfo"
...@@ -20,6 +21,9 @@ import ( ...@@ -20,6 +21,9 @@ import (
var log = logging.Logger("filestore") var log = logging.Logger("filestore")
var ErrFilestoreNotEnabled = errors.New("filestore is not enabled, see https://git.io/vNItf")
var ErrUrlstoreNotEnabled = errors.New("urlstore is not enabled")
// Filestore implements a Blockstore by combining a standard Blockstore // Filestore implements a Blockstore by combining a standard Blockstore
// to store regular blocks and a special Blockstore called // to store regular blocks and a special Blockstore called
// FileManager to store blocks which data exists in an external file. // FileManager to store blocks which data exists in an external file.
......
...@@ -159,7 +159,7 @@ func unmarshalDataObj(o interface{}) (*pb.DataObj, error) { ...@@ -159,7 +159,7 @@ func unmarshalDataObj(o interface{}) (*pb.DataObj, error) {
func (f *FileManager) readFileDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) { func (f *FileManager) readFileDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) {
if !f.AllowFiles { if !f.AllowFiles {
return nil, fmt.Errorf("filestore not enabled") return nil, ErrFilestoreNotEnabled
} }
p := filepath.FromSlash(d.GetFilePath()) p := filepath.FromSlash(d.GetFilePath())
...@@ -202,7 +202,7 @@ func (f *FileManager) readFileDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) ...@@ -202,7 +202,7 @@ func (f *FileManager) readFileDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error)
// reads and verifies the block from URL // reads and verifies the block from URL
func (f *FileManager) readURLDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) { func (f *FileManager) readURLDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) {
if !f.AllowUrls { if !f.AllowUrls {
return nil, fmt.Errorf("urlstore not enabled") return nil, ErrUrlstoreNotEnabled
} }
req, err := http.NewRequest("GET", d.GetFilePath(), nil) req, err := http.NewRequest("GET", d.GetFilePath(), nil)
...@@ -267,12 +267,12 @@ func (f *FileManager) putTo(b *posinfo.FilestoreNode, to putter) error { ...@@ -267,12 +267,12 @@ func (f *FileManager) putTo(b *posinfo.FilestoreNode, to putter) error {
if IsURL(b.PosInfo.FullPath) { if IsURL(b.PosInfo.FullPath) {
if !f.AllowUrls { if !f.AllowUrls {
return fmt.Errorf("urlstore not enabled") return ErrUrlstoreNotEnabled
} }
dobj.FilePath = proto.String(b.PosInfo.FullPath) dobj.FilePath = proto.String(b.PosInfo.FullPath)
} else { } else {
if !f.AllowFiles { if !f.AllowFiles {
return fmt.Errorf("filestore not enabled") return ErrFilestoreNotEnabled
} }
if !filepath.HasPrefix(b.PosInfo.FullPath, f.root) { if !filepath.HasPrefix(b.PosInfo.FullPath, f.root) {
return fmt.Errorf("cannot add filestore references outside ipfs root (%s)", f.root) return fmt.Errorf("cannot add filestore references outside ipfs root (%s)", f.root)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论