added implements check for root types and fixed remaining interfaces on nodes
Henry committed
Feb 28, 2015 at 22:50 UTC
94f55f2d51303577f9623185dcfe3794759899bb
2 files changed
+36
-16
fuse/ipns/ipns_unix.go
+22
-11
@@ -167,7 +167,7 @@ func (*Root) Attr() fuse.Attr {
167
}
168
169
// Lookup performs a lookup under this node.
170
-func (s *Root) Lookup(name string, ctx context.Context) (fs.Node, error) {
170
+func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
171
switch name {
172
case "mach_kernel", ".hidden", "._.":
173
// Just quiet some log noise on OS X.
@@ -195,8 +195,8 @@ func (s *Root) Lookup(name string, ctx context.Context) (fs.Node, error) {
195
return &Link{s.IpfsRoot + "/" + resolved.B58String()}, nil
196
}
197
198
-// ReadDir reads a particular directory. Disallowed for root.
199
-func (r *Root) ReadDir(ctx context.Context) ([]fuse.Dirent, error) {
198
+// ReadDirAll reads a particular directory. Disallowed for root.
199
+func (r *Root) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
200
listing := []fuse.Dirent{
201
fuse.Dirent{
202
Name: "local",
@@ -285,7 +285,7 @@ func (s *Node) Attr() fuse.Attr {
285
}
286
287
// Lookup performs a lookup under this node.
288
-func (s *Node) Lookup(name string, ctx context.Context) (fs.Node, error) {
288
+func (s *Node) Lookup(ctx context.Context, name string) (fs.Node, error) {
289
nodes, err := s.Ipfs.Resolver.ResolveLinks(s.Nd, []string{name})
290
if err != nil {
291
// todo: make this error more versatile.
@@ -314,8 +314,8 @@ func (n *Node) makeChild(name string, node *mdag.Node) *Node {
314
return child
315
}
316
317
-// ReadDir reads the link structure as directory entries
318
-func (s *Node) ReadDir(ctx context.Context) ([]fuse.Dirent, error) {
317
+// ReadDirAll reads the link structure as directory entries
318
+func (s *Node) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
319
entries := make([]fuse.Dirent, len(s.Nd.Links))
320
for i, link := range s.Nd.Links {
321
n := link.Name
@@ -331,7 +331,7 @@ func (s *Node) ReadDir(ctx context.Context) ([]fuse.Dirent, error) {
331
return nil, fuse.ENOENT
332
}
333
334
-func (s *Node) Read(req *fuse.ReadRequest, resp *fuse.ReadResponse, ctx context.Context) error {
334
+func (s *Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
335
k, err := s.Nd.Key()
336
if err != nil {
337
return err
@@ -627,17 +627,28 @@ func (n *Node) update(name string, newnode *mdag.Node) error {
627
}
628
629
// to check that out Node implements all the interfaces we want
630
-type ipnsNode interface {
630
+type ipnsRoot interface {
631
fs.Node
632
- fs.HandleWriter
632
+ fs.HandleReadDirAller
633
+ fs.NodeStringLookuper
634
+}
635
+
636
+var _ ipnsRoot = (*Root)(nil)
637
+
638
+type ipnsNode interface {
639
fs.HandleFlusher
640
+ fs.HandleReadDirAller
641
+ fs.HandleReader
642
+ fs.HandleWriter
643
+ fs.Node
644
+ fs.NodeCreater
645
fs.NodeFsyncer
646
fs.NodeMkdirer
636
- fs.NodeOpener
647
fs.NodeMknoder
638
- fs.NodeCreater
648
+ fs.NodeOpener
649
fs.NodeRemover
650
fs.NodeRenamer
651
+ fs.NodeStringLookuper
652
}
653
654
var _ ipnsNode = (*Node)(nil)
fuse/readonly/readonly_unix.go
+14
-5
@@ -67,8 +67,8 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
67
return &Node{Ipfs: s.Ipfs, Nd: nd}, nil
68
}
69
70
-// ReadDir reads a particular directory. Disallowed for root.
71
-func (*Root) ReadDir(ctx context.Context) ([]fuse.Dirent, error) {
70
+// ReadDirAll reads a particular directory. Disallowed for root.
71
+func (*Root) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
72
log.Debug("Read Root.")
73
return nil, fuse.EPERM
74
}
@@ -127,8 +127,8 @@ func (s *Node) Lookup(ctx context.Context, name string) (fs.Node, error) {
127
return &Node{Ipfs: s.Ipfs, Nd: nodes[len(nodes)-1]}, nil
128
}
129
130
-// ReadDir reads the link structure as directory entries
131
-func (s *Node) ReadDir(ctx context.Context) ([]fuse.Dirent, error) {
130
+// ReadDirAll reads the link structure as directory entries
131
+func (s *Node) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
132
log.Debug("Node ReadDir")
133
entries := make([]fuse.Dirent, len(s.Nd.Links))
134
for i, link := range s.Nd.Links {
@@ -180,10 +180,19 @@ func (s *Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadR
180
}
181
182
// to check that out Node implements all the interfaces we want
183
-type roNode interface {
183
+type roRoot interface {
184
fs.Node
185
+ fs.HandleReadDirAller
186
fs.NodeStringLookuper
187
+}
188
+
189
+var _ roRoot = (*Root)(nil)
190
+
191
+type roNode interface {
192
+ fs.HandleReadDirAller
193
fs.HandleReader
194
+ fs.Node
195
+ fs.NodeStringLookuper
196
}
197
198
var _ roNode = (*Node)(nil)