Code cleanups to make code climate happy.
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
Kevin Atkinson committed
Jun 26, 2018 at 15:55 UTC
ed2bb81b8d0951fe8433d39cb8ff9d433b3a90b2
3 files changed
+12
-11
core/commands/root.go
+1
-1
@@ -136,7 +136,7 @@ var rootSubcommands = map[string]*cmds.Command{
136
"tar": lgc.NewCommand(TarCmd),
137
"file": lgc.NewCommand(unixfs.UnixFSCmd),
138
"update": lgc.NewCommand(ExternalBinary()),
139
- "urlstore": lgc.NewCommand(UrlStoreCmd),
139
+ "urlstore": lgc.NewCommand(urlStoreCmd),
140
"version": lgc.NewCommand(VersionCmd),
141
"shutdown": lgc.NewCommand(daemonShutdownCmd),
142
}
core/commands/urlstore.go
+1
-1
@@ -16,7 +16,7 @@ import (
16
cmdkit "gx/ipfs/QmdE4gMduCKCGAcczM2F5ioYDfdeKuPix138wrES1YSr7f/go-ipfs-cmdkit"
17
)
18
19
-var UrlStoreCmd = &cmds.Command{
19
+var urlStoreCmd = &cmds.Command{
20
21
Subcommands: map[string]*cmds.Command{
22
"add": urlAdd,
filestore/fsrefstore.go
+10
-9
@@ -123,11 +123,10 @@ func (f *FileManager) Get(c *cid.Cid) (blocks.Block, error) {
123
}
124
125
func (f *FileManager) readDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) {
126
- if !IsURL(d.GetFilePath()) {
127
- return f.readFileDataObj(c, d)
128
- } else {
126
+ if IsURL(d.GetFilePath()) {
127
return f.readURLDataObj(c, d)
128
}
129
+ return f.readFileDataObj(c, d)
130
}
131
132
func (f *FileManager) getDataObj(c *cid.Cid) (*pb.DataObj, error) {
@@ -266,7 +265,12 @@ func (f *FileManager) Put(b *posinfo.FilestoreNode) error {
265
func (f *FileManager) putTo(b *posinfo.FilestoreNode, to putter) error {
266
var dobj pb.DataObj
267
269
- if !IsURL(b.PosInfo.FullPath) {
268
+ if IsURL(b.PosInfo.FullPath) {
269
+ if !f.AllowUrls {
270
+ return fmt.Errorf("urlstore not enabled")
271
+ }
272
+ dobj.FilePath = proto.String(b.PosInfo.FullPath)
273
+ } else {
274
if !f.AllowFiles {
275
return fmt.Errorf("filestore not enabled")
276
}
@@ -280,11 +284,6 @@ func (f *FileManager) putTo(b *posinfo.FilestoreNode, to putter) error {
284
}
285
286
dobj.FilePath = proto.String(filepath.ToSlash(p))
283
- } else {
284
- if !f.AllowUrls {
285
- return fmt.Errorf("urlstore not enabled")
286
- }
287
- dobj.FilePath = proto.String(b.PosInfo.FullPath)
287
}
288
dobj.Offset = proto.Uint64(b.PosInfo.Offset)
289
dobj.Size_ = proto.Uint64(uint64(len(b.RawData())))
@@ -314,6 +313,8 @@ func (f *FileManager) PutMany(bs []*posinfo.FilestoreNode) error {
313
return batch.Commit()
314
}
315
316
+// IsURL returns true if the string represents a valid URL that the
317
+// urlstore can handle.
318
func IsURL(str string) bool {
319
return (len(str) > 7 && str[0] == 'h' && str[1] == 't' && str[2] == 't' && str[3] == 'p') &&
320
((len(str) > 8 && str[4] == 's' && str[5] == ':' && str[6] == '/' && str[7] == '/') ||