diff --git a/core/commands/add.go b/core/commands/add.go index 43520bcca..46204c06d 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -10,6 +10,7 @@ import ( blockservice "github.com/ipfs/go-ipfs/blockservice" core "github.com/ipfs/go-ipfs/core" "github.com/ipfs/go-ipfs/core/coreunix" + filestore "github.com/ipfs/go-ipfs/filestore" dag "github.com/ipfs/go-ipfs/merkledag" dagtest "github.com/ipfs/go-ipfs/merkledag/test" mfs "github.com/ipfs/go-ipfs/mfs" @@ -183,8 +184,7 @@ You can now check what blocks have been created by: // nocopy -> filestoreEnabled if nocopy && !cfg.Experimental.FilestoreEnabled { - res.SetError(errors.New("filestore is not enabled, see https://git.io/vNItf"), - cmdkit.ErrClient) + res.SetError(filestore.ErrFilestoreNotEnabled, cmdkit.ErrClient) return } diff --git a/core/commands/filestore.go b/core/commands/filestore.go index effd28e9e..f24be1410 100644 --- a/core/commands/filestore.go +++ b/core/commands/filestore.go @@ -237,7 +237,7 @@ func getFilestore(env interface{}) (*core.IpfsNode, *filestore.Filestore, error) } fs := n.Filestore if fs == nil { - return n, nil, fmt.Errorf("filestore not enabled") + return n, nil, filestore.ErrFilestoreNotEnabled } return n, fs, err } diff --git a/core/commands/urlstore.go b/core/commands/urlstore.go index a0a25be73..80f9eb679 100644 --- a/core/commands/urlstore.go +++ b/core/commands/urlstore.go @@ -7,6 +7,7 @@ import ( "strings" cmds "github.com/ipfs/go-ipfs/commands" + filestore "github.com/ipfs/go-ipfs/filestore" balanced "github.com/ipfs/go-ipfs/importer/balanced" ihelper "github.com/ipfs/go-ipfs/importer/helpers" @@ -63,7 +64,7 @@ time. } if !cfg.Experimental.UrlstoreEnabled { - res.SetError(fmt.Errorf("URL store not enabled."), cmdkit.ErrNormal) + res.SetError(filestore.ErrUrlstoreNotEnabled, cmdkit.ErrNormal) return } diff --git a/filestore/filestore.go b/filestore/filestore.go index 66289b068..0c80fb1d5 100644 --- a/filestore/filestore.go +++ b/filestore/filestore.go @@ -9,6 +9,7 @@ package filestore import ( "context" + "errors" blocks "gx/ipfs/QmTRCUvZLiir12Qr6MV3HKfKMHX8Nf1Vddn6t2g5nsQSb9/go-block-format" posinfo "gx/ipfs/QmUWsXLvYYDAaoAt9TPZpFX4ffHHMg46AHrz1ZLTN5ABbe/go-ipfs-posinfo" @@ -20,6 +21,9 @@ import ( 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 // to store regular blocks and a special Blockstore called // FileManager to store blocks which data exists in an external file. diff --git a/filestore/fsrefstore.go b/filestore/fsrefstore.go index be0be92c7..98255caa7 100644 --- a/filestore/fsrefstore.go +++ b/filestore/fsrefstore.go @@ -159,7 +159,7 @@ func unmarshalDataObj(o interface{}) (*pb.DataObj, error) { func (f *FileManager) readFileDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) { if !f.AllowFiles { - return nil, fmt.Errorf("filestore not enabled") + return nil, ErrFilestoreNotEnabled } p := filepath.FromSlash(d.GetFilePath()) @@ -202,7 +202,7 @@ func (f *FileManager) readFileDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) // reads and verifies the block from URL func (f *FileManager) readURLDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) { if !f.AllowUrls { - return nil, fmt.Errorf("urlstore not enabled") + return nil, ErrUrlstoreNotEnabled } req, err := http.NewRequest("GET", d.GetFilePath(), nil) @@ -267,12 +267,12 @@ func (f *FileManager) putTo(b *posinfo.FilestoreNode, to putter) error { if IsURL(b.PosInfo.FullPath) { if !f.AllowUrls { - return fmt.Errorf("urlstore not enabled") + return ErrUrlstoreNotEnabled } dobj.FilePath = proto.String(b.PosInfo.FullPath) } else { if !f.AllowFiles { - return fmt.Errorf("filestore not enabled") + return ErrFilestoreNotEnabled } if !filepath.HasPrefix(b.PosInfo.FullPath, f.root) { return fmt.Errorf("cannot add filestore references outside ipfs root (%s)", f.root)