From a2f15faa4c791b8c803cdaf9bd750b2a632052c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 18 Dec 2018 02:09:43 +0100 Subject: [PATCH] files2.0: address review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit License: MIT Signed-off-by: Ɓukasz Magiera --- cmd/ipfs/init.go | 12 ++++++++---- core/commands/cat.go | 2 +- core/commands/cmdenv/file.go | 1 + core/coreapi/interface/errors.go | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/ipfs/init.go b/cmd/ipfs/init.go index b68cb13af95..8f7796a0ea9 100644 --- a/cmd/ipfs/init.go +++ b/cmd/ipfs/init.go @@ -87,15 +87,19 @@ environment variable: f := req.Files if f != nil { it := req.Files.Entries() - if !it.Next() && it.Err() != nil { - return it.Err() + if !it.Next() { + if it.Err() != nil { + return it.Err() + } + return fmt.Errorf("file argument was nil") } - if files.FileFromEntry(it) == nil { + file := files.FileFromEntry(it) + if file == nil { return fmt.Errorf("expected a regular file") } conf = &config.Config{} - if err := json.NewDecoder(files.FileFromEntry(it)).Decode(conf); err != nil { + if err := json.NewDecoder(file).Decode(conf); err != nil { return err } } diff --git a/core/commands/cat.go b/core/commands/cat.go index 734316927ec..fe25d6dc7d0 100644 --- a/core/commands/cat.go +++ b/core/commands/cat.go @@ -130,7 +130,7 @@ func cat(ctx context.Context, api iface.CoreAPI, paths []string, offset int64, m file, ok := f.(files.File) if !ok { - return nil, 0, iface.ErrIsDir + return nil, 0, iface.ErrNotFile } fsize, err := file.Size() diff --git a/core/commands/cmdenv/file.go b/core/commands/cmdenv/file.go index de162b0d22c..c25505dc801 100644 --- a/core/commands/cmdenv/file.go +++ b/core/commands/cmdenv/file.go @@ -6,6 +6,7 @@ import ( files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files" ) +// GetFileArg returns the next file from the directory or an error func GetFileArg(it files.DirIterator) (files.File, error) { if !it.Next() { err := it.Err() diff --git a/core/coreapi/interface/errors.go b/core/coreapi/interface/errors.go index 4ee3026ffc7..234abe5667e 100644 --- a/core/coreapi/interface/errors.go +++ b/core/coreapi/interface/errors.go @@ -4,5 +4,6 @@ import "errors" var ( ErrIsDir = errors.New("this dag node is a directory") + ErrNotFile = errors.New("this dag node is not a regular file") ErrOffline = errors.New("this action must be run in online mode, try running 'ipfs daemon' first") )