diff --git a/cmd/ipfs/init.go b/cmd/ipfs/init.go index e78b36584..2ee7488ac 100644 --- a/cmd/ipfs/init.go +++ b/cmd/ipfs/init.go @@ -19,6 +19,7 @@ import ( "gx/ipfs/QmYyzmMnhNTtoXx5ttgUaRdHHckYnQWjPL98hgLAR2QLDD/go-ipfs-config" "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds" "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit" + "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files" ) const ( @@ -89,12 +90,12 @@ environment variable: if !it.Next() && it.Err() != nil { return it.Err() } - if it.File() == nil { + if files.FileFrom(it) == nil { return fmt.Errorf("expected a regular file") } conf = &config.Config{} - if err := json.NewDecoder(it.File()).Decode(conf); err != nil { + if err := json.NewDecoder(files.FileFrom(it)).Decode(conf); err != nil { return err } } diff --git a/core/commands/block.go b/core/commands/block.go index 670056098..ec7f6baf4 100644 --- a/core/commands/block.go +++ b/core/commands/block.go @@ -13,6 +13,7 @@ import ( cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds" cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit" + files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files" mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash" ) @@ -157,7 +158,7 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1. if !it.Next() && it.Err() != nil { return it.Err() } - if it.File() == nil { + if files.FileFrom(it) == nil { return fmt.Errorf("expected a regular file") } @@ -181,7 +182,7 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1. } } - p, err := api.Block().Put(req.Context, it.File(), options.Block.Hash(mhtval, mhlen), options.Block.Format(format)) + p, err := api.Block().Put(req.Context, files.FileFrom(it), options.Block.Hash(mhtval, mhlen), options.Block.Format(format)) if err != nil { return err } diff --git a/core/commands/config.go b/core/commands/config.go index 787bba0d7..ad6f6f30e 100644 --- a/core/commands/config.go +++ b/core/commands/config.go @@ -18,6 +18,7 @@ import ( config "gx/ipfs/QmYyzmMnhNTtoXx5ttgUaRdHHckYnQWjPL98hgLAR2QLDD/go-ipfs-config" cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds" cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit" + files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files" ) // ConfigUpdateOutput is config profile apply command's output @@ -284,10 +285,10 @@ can't be undone. if !it.Next() && it.Err() != nil { return it.Err() } - if it.File() == nil { + if files.FileFrom(it) == nil { return fmt.Errorf("expected a regular file") } - file := it.File() + file := files.FileFrom(it) defer file.Close() return replaceConfig(r, file) diff --git a/core/commands/dag/dag.go b/core/commands/dag/dag.go index 21714630f..62f9e1898 100644 --- a/core/commands/dag/dag.go +++ b/core/commands/dag/dag.go @@ -14,6 +14,7 @@ import ( cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds" ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format" cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit" + files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files" mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash" ) @@ -94,10 +95,10 @@ into an object of the specified format. it := req.Files.Entries() for it.Next() { - if it.File() == nil { + if files.FileFrom(it) == nil { return fmt.Errorf("expected a regular file") } - nds, err := coredag.ParseInputs(ienc, format, it.File(), mhType, -1) + nds, err := coredag.ParseInputs(ienc, format, files.FileFrom(it), mhType, -1) if err != nil { return err } diff --git a/core/commands/files.go b/core/commands/files.go index 20fce2bfc..da567067e 100644 --- a/core/commands/files.go +++ b/core/commands/files.go @@ -25,6 +25,7 @@ import ( logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log" dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag" cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit" + files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files" mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash" ) @@ -773,11 +774,11 @@ stat' on the file or any of its ancestors. if !it.Next() && it.Err() != nil { return it.Err() } - if it.File() == nil { + if files.FileFrom(it) == nil { return fmt.Errorf("expected a regular file") } - var r io.Reader = it.File() + var r io.Reader = files.FileFrom(it) if countfound { r = io.LimitReader(r, int64(count)) } diff --git a/core/commands/object/object.go b/core/commands/object/object.go index b3ccc3b72..8b6dfea59 100644 --- a/core/commands/object/object.go +++ b/core/commands/object/object.go @@ -17,6 +17,7 @@ import ( ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format" dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag" cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit" + files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files" ) type Node struct { @@ -395,7 +396,7 @@ And then run: if !it.Next() && it.Err() != nil { return it.Err() } - if it.File() == nil { + if files.FileFrom(it) == nil { return fmt.Errorf("expected a regular file") } @@ -414,7 +415,7 @@ And then run: return err } - p, err := api.Object().Put(req.Context, it.File(), + p, err := api.Object().Put(req.Context, files.FileFrom(it), options.Object.DataType(datafieldenc), options.Object.InputEnc(inputenc), options.Object.Pin(dopin)) diff --git a/core/commands/object/patch.go b/core/commands/object/patch.go index 058fa661a..52ce58ce2 100644 --- a/core/commands/object/patch.go +++ b/core/commands/object/patch.go @@ -10,6 +10,7 @@ import ( "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds" "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit" + "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files" ) var ObjectPatchCmd = &cmds.Command{ @@ -64,11 +65,11 @@ the limit will not be respected by the network. if !it.Next() && it.Err() != nil { return it.Err() } - if it.File() == nil { + if files.FileFrom(it) == nil { return fmt.Errorf("expected a regular file") } - p, err := api.Object().AppendData(req.Context, root, it.File()) + p, err := api.Object().AppendData(req.Context, root, files.FileFrom(it)) if err != nil { return err } @@ -114,11 +115,11 @@ Example: if !it.Next() && it.Err() != nil { return it.Err() } - if it.File() == nil { + if files.FileFrom(it) == nil { return fmt.Errorf("expected a regular file") } - p, err := api.Object().SetData(req.Context, root, it.File()) + p, err := api.Object().SetData(req.Context, root, files.FileFrom(it)) if err != nil { return err } diff --git a/core/commands/tar.go b/core/commands/tar.go index 92939a1eb..18074063c 100644 --- a/core/commands/tar.go +++ b/core/commands/tar.go @@ -13,6 +13,7 @@ import ( cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds" dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag" cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit" + files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files" ) var TarCmd = &cmds.Command{ @@ -48,11 +49,11 @@ represent it. if !it.Next() && it.Err() != nil { return it.Err() } - if it.File() == nil { + if files.FileFrom(it) == nil { return fmt.Errorf("expected a regular file") } - node, err := tar.ImportTar(req.Context, it.File(), nd.DAG) + node, err := tar.ImportTar(req.Context, files.FileFrom(it), nd.DAG) if err != nil { return err } diff --git a/core/coreapi/name_test.go b/core/coreapi/name_test.go index 85049b8b8..c97c08323 100644 --- a/core/coreapi/name_test.go +++ b/core/coreapi/name_test.go @@ -4,7 +4,6 @@ import ( "context" "github.com/ipfs/go-ipfs/core" "io" - "io/ioutil" "math/rand" "path" "testing" @@ -20,7 +19,7 @@ import ( var rnd = rand.New(rand.NewSource(0x62796532303137)) func addTestObject(ctx context.Context, api coreiface.CoreAPI) (coreiface.Path, error) { - return api.Unixfs().Add(ctx, files.NewReaderFile(ioutil.NopCloser(&io.LimitedReader{R: rnd, N: 4092}), nil)) + return api.Unixfs().Add(ctx, files.FileFrom(&io.LimitedReader{R: rnd, N: 4092})) } func appendPath(p coreiface.Path, sub string) coreiface.Path { diff --git a/core/coreapi/unixfile.go b/core/coreapi/unixfile.go index 1ec15ea37..7aa60febd 100644 --- a/core/coreapi/unixfile.go +++ b/core/coreapi/unixfile.go @@ -42,16 +42,6 @@ func (it *ufsIterator) Node() files.Node { return it.curFile } -func (it *ufsIterator) File() files.File { - f, _ := it.curFile.(files.File) - return f -} - -func (it *ufsIterator) Dir() files.Directory { - d, _ := it.curFile.(files.Directory) - return d -} - func (it *ufsIterator) Next() bool { l, ok := <-it.files if !ok { diff --git a/core/coreapi/unixfs_test.go b/core/coreapi/unixfs_test.go index 0ce78665c..9c6f02720 100644 --- a/core/coreapi/unixfs_test.go +++ b/core/coreapi/unixfs_test.go @@ -136,34 +136,34 @@ func makeAPI(ctx context.Context) (*core.IpfsNode, coreiface.CoreAPI, error) { func strFile(data string) func() files.Node { return func() files.Node { - return files.NewReaderFile(ioutil.NopCloser(strings.NewReader(data)), nil) + return files.FileFrom([]byte(data)) } } func twoLevelDir() func() files.Node { return func() files.Node { - return files.NewSliceFile([]files.DirEntry{ - files.FileEntry("abc", files.NewSliceFile([]files.DirEntry{ - files.FileEntry("def", files.NewReaderFile(ioutil.NopCloser(strings.NewReader("world")), nil)), - })), + return files.DirFrom(map[string]files.Node{ + "abc": files.DirFrom(map[string]files.Node{ + "def": files.FileFrom([]byte("world")), + }), - files.FileEntry("bar", files.NewReaderFile(ioutil.NopCloser(strings.NewReader("hello2")), nil)), - files.FileEntry("foo", files.NewReaderFile(ioutil.NopCloser(strings.NewReader("hello1")), nil)), + "bar": files.FileFrom([]byte("hello2")), + "foo": files.FileFrom([]byte("hello1")), }) } } func flatDir() files.Node { - return files.NewSliceFile([]files.DirEntry{ - files.FileEntry("bar", files.NewReaderFile(ioutil.NopCloser(strings.NewReader("hello2")), nil)), - files.FileEntry("foo", files.NewReaderFile(ioutil.NopCloser(strings.NewReader("hello1")), nil)), + return files.DirFrom(map[string]files.Node{ + "bar": files.FileFrom([]byte("hello2")), + "foo": files.FileFrom([]byte("hello1")), }) } func wrapped(name string) func(f files.Node) files.Node { return func(f files.Node) files.Node { - return files.NewSliceFile([]files.DirEntry{ - files.FileEntry(name, f), + return files.DirFrom(map[string]files.Node{ + name: f, }) } } @@ -296,7 +296,7 @@ func TestAdd(t *testing.T) { name: "addWrapped", path: "/ipfs/QmVE9rNpj5doj7XHzp5zMUxD7BJgXEqx4pe3xZ3JBReWHE", data: func() files.Node { - return files.NewReaderFile(ioutil.NopCloser(strings.NewReader(helloStr)), nil) + return files.FileFrom([]byte(helloStr)) }, wrap: "foo", expect: wrapped("foo"), @@ -306,7 +306,7 @@ func TestAdd(t *testing.T) { name: "addNotWrappedDirFile", path: hello, data: func() files.Node { - return files.NewReaderFile(ioutil.NopCloser(strings.NewReader(helloStr)), nil) + return files.FileFrom([]byte(helloStr)) }, wrap: "foo", }, @@ -314,11 +314,11 @@ func TestAdd(t *testing.T) { name: "stdinWrapped", path: "/ipfs/QmU3r81oZycjHS9oaSHw37ootMFuFUw1DvMLKXPsezdtqU", data: func() files.Node { - return files.NewReaderFile(ioutil.NopCloser(strings.NewReader(helloStr)), nil) + return files.FileFrom([]byte(helloStr)) }, expect: func(files.Node) files.Node { - return files.NewSliceFile([]files.DirEntry{ - files.FileEntry("QmQy2Dw4Wk7rdJKjThjYXzfFJNaRKRHhHP5gHHXroJMYxk", files.NewReaderFile(ioutil.NopCloser(strings.NewReader(helloStr)), nil)), + return files.DirFrom(map[string]files.Node{ + "QmQy2Dw4Wk7rdJKjThjYXzfFJNaRKRHhHP5gHHXroJMYxk": files.FileFrom([]byte(helloStr)), }) }, opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true)}, @@ -335,8 +335,8 @@ func TestAdd(t *testing.T) { return rf }, expect: func(files.Node) files.Node { - return files.NewSliceFile([]files.DirEntry{ - files.FileEntry("test", files.NewReaderFile(ioutil.NopCloser(strings.NewReader(helloStr)), nil)), + return files.DirFrom(map[string]files.Node{ + "test": files.FileFrom([]byte(helloStr)), }) }, opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true), options.Unixfs.StdinName("test")}, @@ -361,10 +361,10 @@ func TestAdd(t *testing.T) { { name: "hiddenFiles", data: func() files.Node { - return files.NewSliceFile([]files.DirEntry{ - files.FileEntry(".bar", files.NewReaderFile(ioutil.NopCloser(strings.NewReader("hello2")), nil)), - files.FileEntry("bar", files.NewReaderFile(ioutil.NopCloser(strings.NewReader("hello2")), nil)), - files.FileEntry("foo", files.NewReaderFile(ioutil.NopCloser(strings.NewReader("hello1")), nil)), + return files.DirFrom(map[string]files.Node{ + ".bar": files.FileFrom([]byte("hello2")), + "bar": files.FileFrom([]byte("hello2")), + "foo": files.FileFrom([]byte("hello1")), }) }, wrap: "t", @@ -374,7 +374,7 @@ func TestAdd(t *testing.T) { { name: "hiddenFileAlwaysAdded", data: func() files.Node { - return files.NewReaderFile(ioutil.NopCloser(strings.NewReader(helloStr)), nil) + return files.FileFrom([]byte(helloStr)) }, wrap: ".foo", path: hello, @@ -382,10 +382,10 @@ func TestAdd(t *testing.T) { { name: "hiddenFilesNotAdded", data: func() files.Node { - return files.NewSliceFile([]files.DirEntry{ - files.FileEntry(".bar", files.NewReaderFile(ioutil.NopCloser(strings.NewReader("hello2")), nil)), - files.FileEntry("bar", files.NewReaderFile(ioutil.NopCloser(strings.NewReader("hello2")), nil)), - files.FileEntry("foo", files.NewReaderFile(ioutil.NopCloser(strings.NewReader("hello1")), nil)), + return files.DirFrom(map[string]files.Node{ + ".bar": files.FileFrom([]byte("hello2")), + "bar": files.FileFrom([]byte("hello2")), + "foo": files.FileFrom([]byte("hello1")), }) }, expect: func(files.Node) files.Node { @@ -432,8 +432,7 @@ func TestAdd(t *testing.T) { { name: "progress1M", data: func() files.Node { - r := bytes.NewReader(bytes.Repeat([]byte{0}, 1000000)) - return files.NewReaderFile(ioutil.NopCloser(r), nil) + return files.FileFrom(bytes.NewReader(bytes.Repeat([]byte{0}, 1000000))) }, path: "/ipfs/QmXXNNbwe4zzpdMg62ZXvnX1oU7MwSrQ3vAEtuwFKCm1oD", events: []coreiface.AddEvent{ diff --git a/core/coreunix/add_test.go b/core/coreunix/add_test.go index fe9e1e0d6..398ae7bc4 100644 --- a/core/coreunix/add_test.go +++ b/core/coreunix/add_test.go @@ -71,20 +71,18 @@ func TestAddGCLive(t *testing.T) { } adder.Out = out - dataa := ioutil.NopCloser(bytes.NewBufferString("testfileA")) - rfa := files.NewReaderFile(dataa, nil) + rfa := files.FileFrom([]byte("testfileA")) // make two files with pipes so we can 'pause' the add for timing of the test piper, pipew := io.Pipe() - hangfile := files.NewReaderFile(piper, nil) + hangfile := files.FileFrom(piper) - datad := ioutil.NopCloser(bytes.NewBufferString("testfileD")) - rfd := files.NewReaderFile(datad, nil) + rfd := files.FileFrom([]byte("testfileD")) - slf := files.NewSliceFile([]files.DirEntry{ - files.FileEntry("a", rfa), - files.FileEntry("b", hangfile), - files.FileEntry("d", rfd), + slf := files.DirFrom(map[string]files.Node{ + "a": rfa, + "b": hangfile, + "d": rfd, }) addDone := make(chan struct{})