From eeb15db140c48ec3f003fb6573def4f9fd2bb801 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Thu, 1 Feb 2018 15:51:02 -0500 Subject: [PATCH] Move files.go out of its own directory. It is a single file so putting it in its own package is a bit of an overkill. License: MIT Signed-off-by: Kevin Atkinson --- core/commands/{files => }/files.go | 20 +++----------------- core/commands/files/env.go | 29 ----------------------------- core/commands/root.go | 3 +-- 3 files changed, 4 insertions(+), 48 deletions(-) rename core/commands/{files => }/files.go (98%) delete mode 100644 core/commands/files/env.go diff --git a/core/commands/files/files.go b/core/commands/files.go similarity index 98% rename from core/commands/files/files.go rename to core/commands/files.go index 9d6861502..19288b392 100644 --- a/core/commands/files/files.go +++ b/core/commands/files.go @@ -31,7 +31,7 @@ import ( ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format" ) -var log = logging.Logger("cmds/files") +var flog = logging.Logger("cmds/files") var FilesCmd = &cmds.Command{ Helptext: cmdkit.HelpText{ @@ -768,7 +768,7 @@ stat' on the file or any of its ancestors. _, err = wfd.Seek(int64(offset), io.SeekStart) if err != nil { - log.Error("seekfail: ", err) + flog.Error("seekfail: ", err) res.SetError(err, cmdkit.ErrNormal) return } @@ -1112,7 +1112,7 @@ func getFileHandle(r *mfs.Root, path string, create bool, prefix *cid.Prefix) (* dirname, fname := gopath.Split(path) pdiri, err := mfs.Lookup(r, dirname) if err != nil { - log.Error("lookupfail ", dirname) + flog.Error("lookupfail ", dirname) return nil, err } pdir, ok := pdiri.(*mfs.Directory) @@ -1161,17 +1161,3 @@ func checkPath(p string) (string, error) { } return cleaned, nil } - -// copy+pasted from ../commands.go -func unwrapOutput(i interface{}) (interface{}, error) { - var ( - ch <-chan interface{} - ok bool - ) - - if ch, ok = i.(<-chan interface{}); !ok { - return nil, e.TypeErr(ch, i) - } - - return <-ch, nil -} diff --git a/core/commands/files/env.go b/core/commands/files/env.go deleted file mode 100644 index d884292e3..000000000 --- a/core/commands/files/env.go +++ /dev/null @@ -1,29 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/ipfs/go-ipfs/commands" - "github.com/ipfs/go-ipfs/core" - "github.com/ipfs/go-ipfs/repo/config" -) - -// GetNode extracts the node from the environment. -func GetNode(env interface{}) (*core.IpfsNode, error) { - ctx, ok := env.(*commands.Context) - if !ok { - return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env) - } - - return ctx.GetNode() -} - -// GetConfig extracts the config from the environment. -func GetConfig(env interface{}) (*config.Config, error) { - ctx, ok := env.(*commands.Context) - if !ok { - return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env) - } - - return ctx.GetConfig() -} diff --git a/core/commands/root.go b/core/commands/root.go index 8e9605945..225fc7ffb 100644 --- a/core/commands/root.go +++ b/core/commands/root.go @@ -7,7 +7,6 @@ import ( oldcmds "github.com/ipfs/go-ipfs/commands" dag "github.com/ipfs/go-ipfs/core/commands/dag" e "github.com/ipfs/go-ipfs/core/commands/e" - files "github.com/ipfs/go-ipfs/core/commands/files" ocmd "github.com/ipfs/go-ipfs/core/commands/object" unixfs "github.com/ipfs/go-ipfs/core/commands/unixfs" @@ -109,7 +108,7 @@ var rootSubcommands = map[string]*cmds.Command{ "block": BlockCmd, "cat": CatCmd, "commands": CommandsDaemonCmd, - "files": files.FilesCmd, + "files": FilesCmd, "filestore": FileStoreCmd, "get": GetCmd, "pubsub": PubsubCmd,