address code review
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Sep 1, 2017 at 14:51 UTC
c5f8a0c11daa676df6ac54b9655760eecfa991c0
3 files changed
+35
-15
fuse/mount/mount.go
+1
-1
@@ -90,7 +90,7 @@ type closer struct {
90
}
91
92
func (c *closer) Close() error {
93
- log.Error(" (c *closer) Close(),", c.M.MountPoint())
93
+ log.Warning(" (c *closer) Close(),", c.M.MountPoint())
94
return c.M.Unmount()
95
}
96
fuse/readonly/readonly_unix.go
+32
-14
@@ -74,9 +74,7 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
74
}
75
76
switch nd := nd.(type) {
77
- case *mdag.ProtoNode:
78
- return &Node{Ipfs: s.Ipfs, Nd: nd}, nil
79
- case *mdag.RawNode:
77
+ case *mdag.ProtoNode, *mdag.RawNode:
78
return &Node{Ipfs: s.Ipfs, Nd: nd}, nil
79
default:
80
log.Error("fuse node was not a protobuf node")
@@ -113,8 +111,6 @@ func (s *Node) Attr(ctx context.Context, a *fuse.Attr) error {
111
a.Mode = 0444
112
a.Size = uint64(len(rawnd.RawData()))
113
a.Blocks = 1
116
- a.Uid = uint32(os.Getuid()) // TODO: should probably cache these calls. No sense making multiple syscalls for each attr call here
117
- a.Gid = uint32(os.Getgid())
114
return nil
115
}
116
@@ -126,26 +122,18 @@ func (s *Node) Attr(ctx context.Context, a *fuse.Attr) error {
122
switch s.cached.GetType() {
123
case ftpb.Data_Directory, ftpb.Data_HAMTShard:
124
a.Mode = os.ModeDir | 0555
129
- a.Uid = uint32(os.Getuid())
130
- a.Gid = uint32(os.Getgid())
125
case ftpb.Data_File:
126
size := s.cached.GetFilesize()
127
a.Mode = 0444
128
a.Size = uint64(size)
129
a.Blocks = uint64(len(s.Nd.Links()))
136
- a.Uid = uint32(os.Getuid())
137
- a.Gid = uint32(os.Getgid())
130
case ftpb.Data_Raw:
131
a.Mode = 0444
132
a.Size = uint64(len(s.cached.GetData()))
133
a.Blocks = uint64(len(s.Nd.Links()))
142
- a.Uid = uint32(os.Getuid())
143
- a.Gid = uint32(os.Getgid())
134
case ftpb.Data_Symlink:
135
a.Mode = 0777 | os.ModeSymlink
136
a.Size = uint64(len(s.cached.GetData()))
147
- a.Uid = uint32(os.Getuid())
148
- a.Gid = uint32(os.Getgid())
137
default:
138
return fmt.Errorf("Invalid data type - %s", s.cached.GetType())
139
}
@@ -198,7 +186,37 @@ func (s *Node) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
186
// will be expensive to query each child. However most shells call an
187
// additional 'stat' on each item in a directory listing, its probably
188
// okay.
201
- entries = append(entries, fuse.Dirent{Name: n, Type: fuse.DT_File})
189
+ nd, err := s.Ipfs.DAG.Get(ctx, lnk.Cid)
190
+ if err != nil {
191
+ log.Warning("error fetching directory child node: ", err)
192
+ }
193
+
194
+ var t fuse.DirentType
195
+ switch nd := nd.(type) {
196
+ case *mdag.RawNode:
197
+ t = fuse.DT_File
198
+ case *mdag.ProtoNode:
199
+ var data ftpb.Data
200
+ if err := proto.Unmarshal(nd.Data(), &data); err != nil {
201
+ log.Warning("failed to unmarshal protonode data field:", err)
202
+ } else {
203
+ switch data.GetType() {
204
+ case ftpb.Data_Directory, ftpb.Data_HAMTShard:
205
+ t = fuse.DT_Dir
206
+ case ftpb.Data_File, ftpb.Data_Raw:
207
+ t = fuse.DT_File
208
+ case ftpb.Data_Symlink:
209
+ t = fuse.DT_Link
210
+ case ftpb.Data_Metadata:
211
+ log.Error("metadata object in fuse should contain its wrapped type")
212
+ default:
213
+ log.Error("unrecognized protonode data type: ", data.GetType())
214
+ }
215
+ }
216
+ default:
217
+ t = fuse.DT_Unknown
218
+ }
219
+ entries = append(entries, fuse.Dirent{Name: n, Type: t})
220
return nil
221
})
222
if err != nil {
merkledag/merkledag.go
+2
@@ -158,6 +158,8 @@ func (sg *sesGetter) Get(ctx context.Context, c *cid.Cid) (node.Node, error) {
158
return nil, ErrNotFound
159
default:
160
return nil, err
161
+ case nil:
162
+ // noop
163
}
164
165
return node.Decode(blk)