mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-02 23:08:07 +08:00
filestore: Return consistent err msg. when file/urlstore is not enabled.
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
This commit is contained in:
parent
6a4b1262a5
commit
8dd970b73a
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user