@cryptotaxi247 / kubo / commits / d588636ce

remove 'Open' from ipnsfs

Jeromy committed Mar 15, 2015 at 17:21 UTC d588636ce82888ec136d60ff99e0a6fe48f12783
3 files changed -163
ipnsfs/dir.go
-32
@@ -38,38 +38,6 @@ func NewDirectory(name string, node *dag.Node, parent childCloser, fs *Filesyste
38 }
39 }
40
41 -// Open opens a file at the given path 'tpath'
42 -func (d *Directory) Open(tpath []string, mode int) (*File, error) {
43 - if len(tpath) == 0 {
44 - return nil, ErrIsDirectory
45 - }
46 - if len(tpath) == 1 {
47 - fi, err := d.childFile(tpath[0])
48 - if err == nil {
49 - return fi, nil
50 - }
51 -
52 - if mode|os.O_CREATE != 0 {
53 - fnode := new(dag.Node)
54 - fnode.Data = ft.FilePBData(nil, 0)
55 - nfi, err := NewFile(tpath[0], fnode, d, d.fs)
56 - if err != nil {
57 - return nil, err
58 - }
59 - d.files[tpath[0]] = nfi
60 - return nfi, nil
61 - }
62 -
63 - return nil, os.ErrNotExist
64 - }
65 -
66 - dir, err := d.childDir(tpath[0])
67 - if err != nil {
68 - return nil, err
69 - }
70 - return dir.Open(tpath[1:], mode)
71 -}
72 -
41 // closeChild updates the child by the given name to the dag node 'nd'
42 // and changes its own dag node, then propogates the changes upward
43 func (d *Directory) closeChild(name string, nd *dag.Node) error {
ipnsfs/system.go
-37
@@ -14,7 +14,6 @@ import (
14 "errors"
15 "fmt"
16 "os"
17 - "strings"
17 "sync"
18 "time"
19
@@ -69,17 +68,6 @@ func NewFilesystem(ctx context.Context, ds dag.DAGService, nsys namesys.NameSyst
68 return fs, nil
69 }
70
72 -// Open opens a file at the given path
73 -func (fs *Filesystem) Open(tpath string, mode int) (*File, error) {
74 - pathelem := strings.Split(tpath, "/")
75 - r, ok := fs.roots[pathelem[0]]
76 - if !ok {
77 - return nil, os.ErrNotExist
78 - }
79 -
80 - return r.Open(pathelem[1:], mode)
81 -}
82 -
71 func (fs *Filesystem) Close() error {
72 wg := sync.WaitGroup{}
73 for _, r := range fs.roots {
@@ -206,31 +194,6 @@ func (kr *KeyRoot) GetValue() FSNode {
194 return kr.val
195 }
196
209 -func (kr *KeyRoot) Open(tpath []string, mode int) (*File, error) {
210 - if kr.val == nil {
211 - // No entry here. KeyRoot was created incorrectly
212 - panic("nil keyroot.val, improperly constructed keyroot")
213 - }
214 - if len(tpath) > 0 {
215 - // Make sure our root is a directory
216 - dir, ok := kr.val.(*Directory)
217 - if !ok {
218 - return nil, os.ErrNotExist
219 - }
220 -
221 - return dir.Open(tpath, mode)
222 - }
223 -
224 - switch t := kr.val.(type) {
225 - case *Directory:
226 - return nil, ErrIsDirectory
227 - case *File:
228 - return t, nil
229 - default:
230 - panic("unrecognized type, should not happen")
231 - }
232 -}
233 -
197 // closeChild implements the childCloser interface, and signals to the publisher that
198 // there are changes ready to be published
199 func (kr *KeyRoot) closeChild(name string, nd *dag.Node) error {
ipnsfs/system_test.go deleted
-94
@@ -1,94 +0,0 @@
1 -package ipnsfs_test
2 -
3 -import (
4 - "bytes"
5 - "io/ioutil"
6 - "os"
7 - "path"
8 - "testing"
9 -
10 - core "github.com/jbenet/go-ipfs/core"
11 - . "github.com/jbenet/go-ipfs/ipnsfs"
12 - u "github.com/jbenet/go-ipfs/util"
13 -)
14 -
15 -func testFS(t *testing.T, nd *core.IpfsNode) *Filesystem {
16 - fs, err := NewFilesystem(nd.Context(), nd.DAG, nd.Namesys, nd.Pinning, nd.PrivateKey)
17 - if err != nil {
18 - t.Fatal(err)
19 - }
20 -
21 - return fs
22 -}
23 -
24 -// Test some basic operations
25 -// testing in fuse/ipns is sufficient to prove this code works properly
26 -func TestBasic(t *testing.T) {
27 - mock, err := core.NewMockNode()
28 - if err != nil {
29 - t.Fatal(err)
30 - }
31 -
32 - fs := testFS(t, mock)
33 -
34 - k := u.Key(mock.Identity)
35 - p := path.Join(k.B58String(), "file")
36 - fi, err := fs.Open(p, os.O_CREATE)
37 - if err != nil {
38 - t.Fatal(err)
39 - }
40 -
41 - data := []byte("Hello World")
42 - n, err := fi.Write(data)
43 - if err != nil {
44 - t.Fatal(err)
45 - }
46 -
47 - if n != len(data) {
48 - t.Fatal("wrote incorrect amount")
49 - }
50 -
51 - err = fi.Close()
52 - if err != nil {
53 - t.Fatal(err)
54 - }
55 -
56 - nfi, err := fs.Open(p, os.O_RDONLY)
57 - if err != nil {
58 - t.Fatal(err)
59 - }
60 -
61 - out, err := ioutil.ReadAll(nfi)
62 - if err != nil {
63 - t.Fatal(err)
64 - }
65 -
66 - err = nfi.Close()
67 - if err != nil {
68 - t.Fatal(err)
69 - }
70 -
71 - if !bytes.Equal(out, data) {
72 - t.Fatal("Write failed.")
73 - }
74 -
75 - err = fs.Close()
76 - if err != nil {
77 - t.Fatal(err)
78 - }
79 -
80 - // Open the filesystem again, and try to read our file
81 - nfs := testFS(t, mock)
82 -
83 - fi, err = nfs.Open(p, os.O_RDONLY)
84 - nb, err := ioutil.ReadAll(fi)
85 - if err != nil {
86 - t.Fatal(err)
87 - }
88 -
89 - t.Log(nb)
90 -
91 - if !bytes.Equal(nb, data) {
92 - t.Fatal("data not the same after closing down fs")
93 - }
94 -}