mirror of
https://github.com/ipfs/kubo.git
synced 2025-10-16 19:24:02 +08:00
Code cleanups to make code climate happy.
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
This commit is contained in:
@ -136,7 +136,7 @@ var rootSubcommands = map[string]*cmds.Command{
|
|||||||
"tar": lgc.NewCommand(TarCmd),
|
"tar": lgc.NewCommand(TarCmd),
|
||||||
"file": lgc.NewCommand(unixfs.UnixFSCmd),
|
"file": lgc.NewCommand(unixfs.UnixFSCmd),
|
||||||
"update": lgc.NewCommand(ExternalBinary()),
|
"update": lgc.NewCommand(ExternalBinary()),
|
||||||
"urlstore": lgc.NewCommand(UrlStoreCmd),
|
"urlstore": lgc.NewCommand(urlStoreCmd),
|
||||||
"version": lgc.NewCommand(VersionCmd),
|
"version": lgc.NewCommand(VersionCmd),
|
||||||
"shutdown": lgc.NewCommand(daemonShutdownCmd),
|
"shutdown": lgc.NewCommand(daemonShutdownCmd),
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
cmdkit "gx/ipfs/QmdE4gMduCKCGAcczM2F5ioYDfdeKuPix138wrES1YSr7f/go-ipfs-cmdkit"
|
cmdkit "gx/ipfs/QmdE4gMduCKCGAcczM2F5ioYDfdeKuPix138wrES1YSr7f/go-ipfs-cmdkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
var UrlStoreCmd = &cmds.Command{
|
var urlStoreCmd = &cmds.Command{
|
||||||
|
|
||||||
Subcommands: map[string]*cmds.Command{
|
Subcommands: map[string]*cmds.Command{
|
||||||
"add": urlAdd,
|
"add": urlAdd,
|
||||||
|
@ -123,11 +123,10 @@ func (f *FileManager) Get(c *cid.Cid) (blocks.Block, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *FileManager) readDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) {
|
func (f *FileManager) readDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) {
|
||||||
if !IsURL(d.GetFilePath()) {
|
if IsURL(d.GetFilePath()) {
|
||||||
return f.readFileDataObj(c, d)
|
|
||||||
} else {
|
|
||||||
return f.readURLDataObj(c, d)
|
return f.readURLDataObj(c, d)
|
||||||
}
|
}
|
||||||
|
return f.readFileDataObj(c, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FileManager) getDataObj(c *cid.Cid) (*pb.DataObj, error) {
|
func (f *FileManager) getDataObj(c *cid.Cid) (*pb.DataObj, error) {
|
||||||
@ -266,7 +265,12 @@ func (f *FileManager) Put(b *posinfo.FilestoreNode) error {
|
|||||||
func (f *FileManager) putTo(b *posinfo.FilestoreNode, to putter) error {
|
func (f *FileManager) putTo(b *posinfo.FilestoreNode, to putter) error {
|
||||||
var dobj pb.DataObj
|
var dobj pb.DataObj
|
||||||
|
|
||||||
if !IsURL(b.PosInfo.FullPath) {
|
if IsURL(b.PosInfo.FullPath) {
|
||||||
|
if !f.AllowUrls {
|
||||||
|
return fmt.Errorf("urlstore not enabled")
|
||||||
|
}
|
||||||
|
dobj.FilePath = proto.String(b.PosInfo.FullPath)
|
||||||
|
} else {
|
||||||
if !f.AllowFiles {
|
if !f.AllowFiles {
|
||||||
return fmt.Errorf("filestore not enabled")
|
return fmt.Errorf("filestore not enabled")
|
||||||
}
|
}
|
||||||
@ -280,11 +284,6 @@ func (f *FileManager) putTo(b *posinfo.FilestoreNode, to putter) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dobj.FilePath = proto.String(filepath.ToSlash(p))
|
dobj.FilePath = proto.String(filepath.ToSlash(p))
|
||||||
} else {
|
|
||||||
if !f.AllowUrls {
|
|
||||||
return fmt.Errorf("urlstore not enabled")
|
|
||||||
}
|
|
||||||
dobj.FilePath = proto.String(b.PosInfo.FullPath)
|
|
||||||
}
|
}
|
||||||
dobj.Offset = proto.Uint64(b.PosInfo.Offset)
|
dobj.Offset = proto.Uint64(b.PosInfo.Offset)
|
||||||
dobj.Size_ = proto.Uint64(uint64(len(b.RawData())))
|
dobj.Size_ = proto.Uint64(uint64(len(b.RawData())))
|
||||||
@ -314,6 +313,8 @@ func (f *FileManager) PutMany(bs []*posinfo.FilestoreNode) error {
|
|||||||
return batch.Commit()
|
return batch.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsURL returns true if the string represents a valid URL that the
|
||||||
|
// urlstore can handle.
|
||||||
func IsURL(str string) bool {
|
func IsURL(str string) bool {
|
||||||
return (len(str) > 7 && str[0] == 'h' && str[1] == 't' && str[2] == 't' && str[3] == 'p') &&
|
return (len(str) > 7 && str[0] == 'h' && str[1] == 't' && str[2] == 't' && str[3] == 'p') &&
|
||||||
((len(str) > 8 && str[4] == 's' && str[5] == ':' && str[6] == '/' && str[7] == '/') ||
|
((len(str) > 8 && str[4] == 's' && str[5] == ':' && str[6] == '/' && str[7] == '/') ||
|
||||||
|
Reference in New Issue
Block a user