@cryptotaxi247 / kubo / commits / a2f15faa4

files2.0: address review

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Dec 18, 2018 at 02:09 UTC a2f15faa4c791b8c803cdaf9bd750b2a632052c3
4 files changed +11 -5
cmd/ipfs/init.go
+8 -4
@@ -87,15 +87,19 @@ environment variable:
87 f := req.Files
88 if f != nil {
89 it := req.Files.Entries()
90 - if !it.Next() && it.Err() != nil {
91 - return it.Err()
90 + if !it.Next() {
91 + if it.Err() != nil {
92 + return it.Err()
93 + }
94 + return fmt.Errorf("file argument was nil")
95 }
93 - if files.FileFromEntry(it) == nil {
96 + file := files.FileFromEntry(it)
97 + if file == nil {
98 return fmt.Errorf("expected a regular file")
99 }
100
101 conf = &config.Config{}
98 - if err := json.NewDecoder(files.FileFromEntry(it)).Decode(conf); err != nil {
102 + if err := json.NewDecoder(file).Decode(conf); err != nil {
103 return err
104 }
105 }
core/commands/cat.go
+1 -1
@@ -130,7 +130,7 @@ func cat(ctx context.Context, api iface.CoreAPI, paths []string, offset int64, m
130
131 file, ok := f.(files.File)
132 if !ok {
133 - return nil, 0, iface.ErrIsDir
133 + return nil, 0, iface.ErrNotFile
134 }
135
136 fsize, err := file.Size()
core/commands/cmdenv/file.go
+1
@@ -6,6 +6,7 @@ import (
6 files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
7 )
8
9 +// GetFileArg returns the next file from the directory or an error
10 func GetFileArg(it files.DirIterator) (files.File, error) {
11 if !it.Next() {
12 err := it.Err()
core/coreapi/interface/errors.go
+1
@@ -4,5 +4,6 @@ import "errors"
4
5 var (
6 ErrIsDir = errors.New("this dag node is a directory")
7 + ErrNotFile = errors.New("this dag node is not a regular file")
8 ErrOffline = errors.New("this action must be run in online mode, try running 'ipfs daemon' first")
9 )