1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-10-16 03:04:58 +08:00

Code cleanups to make code climate happy.

License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
This commit is contained in:
Kevin Atkinson
2018-06-26 15:55:36 -04:00
parent 0e24444280
commit ed2bb81b8d
3 changed files with 12 additions and 11 deletions

View File

@ -136,7 +136,7 @@ var rootSubcommands = map[string]*cmds.Command{
"tar": lgc.NewCommand(TarCmd),
"file": lgc.NewCommand(unixfs.UnixFSCmd),
"update": lgc.NewCommand(ExternalBinary()),
"urlstore": lgc.NewCommand(UrlStoreCmd),
"urlstore": lgc.NewCommand(urlStoreCmd),
"version": lgc.NewCommand(VersionCmd),
"shutdown": lgc.NewCommand(daemonShutdownCmd),
}

View File

@ -16,7 +16,7 @@ import (
cmdkit "gx/ipfs/QmdE4gMduCKCGAcczM2F5ioYDfdeKuPix138wrES1YSr7f/go-ipfs-cmdkit"
)
var UrlStoreCmd = &cmds.Command{
var urlStoreCmd = &cmds.Command{
Subcommands: map[string]*cmds.Command{
"add": urlAdd,

View File

@ -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) {
if !IsURL(d.GetFilePath()) {
return f.readFileDataObj(c, d)
} else {
if IsURL(d.GetFilePath()) {
return f.readURLDataObj(c, d)
}
return f.readFileDataObj(c, d)
}
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 {
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 {
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))
} 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.Size_ = proto.Uint64(uint64(len(b.RawData())))
@ -314,6 +313,8 @@ func (f *FileManager) PutMany(bs []*posinfo.FilestoreNode) error {
return batch.Commit()
}
// IsURL returns true if the string represents a valid URL that the
// urlstore can handle.
func IsURL(str string) bool {
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] == '/') ||