new file creation inside ipns dirs now works
Jeromy committed
Sep 26, 2014 at 15:24 UTC
3b8b9e6847f405724eef226900d65b858476202d
1 file changed
+63
-7
fuse/ipns/ipns_unix.go
+63
-7
@@ -183,6 +183,7 @@ func (r *Root) ReadDir(intr fs.Intr) ([]fuse.Dirent, fuse.Error) {
183
// Node is the core object representing a filesystem tree node.
184
type Node struct {
185
nsRoot *Node
186
+ name string
187
188
// Private keys held by nodes at the root of a keyspace
189
key ci.PrivKey
@@ -192,6 +193,7 @@ type Node struct {
193
fd *mdag.DagReader
194
cached *mdag.PBData
195
196
+ // For writing
197
dataBuf *bytes.Buffer
198
changed bool
199
}
@@ -227,25 +229,30 @@ func (s *Node) Attr() fuse.Attr {
229
230
// Lookup performs a lookup under this node.
231
func (s *Node) Lookup(name string, intr fs.Intr) (fs.Node, fuse.Error) {
230
- log.Debug("ipns: node Lookup '%s'", name)
232
+ log.Debug("ipns: node[%s] Lookup '%s' [intr= %s]", s.name, name, intr.String())
233
nd, err := s.Ipfs.Resolver.ResolveLinks(s.Nd, []string{name})
234
if err != nil {
235
// todo: make this error more versatile.
236
return nil, fuse.ENOENT
237
}
238
239
+ return s.makeChild(name, nd), nil
240
+}
241
+
242
+func (n *Node) makeChild(name string, node *mdag.Node) *Node {
243
child := &Node{
238
- Ipfs: s.Ipfs,
239
- Nd: nd,
244
+ Ipfs: n.Ipfs,
245
+ Nd: node,
246
+ name: name,
247
}
248
242
- if s.nsRoot == nil {
243
- child.nsRoot = s
249
+ if n.nsRoot == nil {
250
+ child.nsRoot = n
251
} else {
245
- child.nsRoot = s.nsRoot
252
+ child.nsRoot = n.nsRoot
253
}
254
248
- return child, nil
255
+ return child
256
}
257
258
// ReadDir reads the link structure as directory entries
@@ -358,6 +365,55 @@ func (n *Node) Fsync(req *fuse.FsyncRequest, intr fs.Intr) fuse.Error {
365
return nil
366
}
367
368
+func (n *Node) Mkdir(req *fuse.MkdirRequest, intr fs.Intr) (fs.Node, fuse.Error) {
369
+ log.Debug("Got mkdir request!")
370
+ dagnd := new(mdag.Node)
371
+ dagnd.Data = mdag.FolderPBData()
372
+ n.Nd.AddNodeLink(req.Name, dagnd)
373
+ n.changed = true
374
+
375
+ child := &Node{
376
+ Ipfs: n.Ipfs,
377
+ Nd: dagnd,
378
+ }
379
+
380
+ if n.nsRoot == nil {
381
+ child.nsRoot = n
382
+ } else {
383
+ child.nsRoot = n.nsRoot
384
+ }
385
+
386
+ return child, nil
387
+}
388
+
389
+func (n *Node) Mknod(req *fuse.MknodRequest, intr fs.Intr) (fs.Node, fuse.Error) {
390
+ log.Debug("Got mknod request!")
391
+ return nil, nil
392
+}
393
+func (n *Node) Open(req *fuse.OpenRequest, resp *fuse.OpenResponse, intr fs.Intr) (fs.Handle, fuse.Error) {
394
+ log.Debug("[%s] Received open request! flags = %s", n.name, req.Flags.String())
395
+ return n, nil
396
+}
397
+
398
+func (n *Node) Create(req *fuse.CreateRequest, resp *fuse.CreateResponse, intr fs.Intr) (fs.Node, fs.Handle, fuse.Error) {
399
+ log.Debug("Got create request!")
400
+ nd := new(mdag.Node)
401
+ nd.Data = mdag.FilePBData(nil)
402
+ child := n.makeChild(req.Name, nd)
403
+
404
+ err := n.Nd.AddNodeLink(req.Name, nd)
405
+ if err != nil {
406
+ log.Error("Error adding child to node: %s", err)
407
+ return nil, nil, fuse.ENOENT
408
+ }
409
+ return child, nil, nil
410
+}
411
+
412
+func (n *Node) Remove(req *fuse.RemoveRequest, intr fs.Intr) fuse.Error {
413
+ log.Debug("Got Remove request!")
414
+ return fuse.EIO
415
+}
416
+
417
// Mount mounts an IpfsNode instance at a particular path. It
418
// serves until the process receives exit signals (to Unmount).
419
func Mount(ipfs *core.IpfsNode, fpath string, ipfspath string) error {