mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 00:39:31 +08:00
new file creation inside ipns dirs now works
This commit is contained in:
@ -183,6 +183,7 @@ func (r *Root) ReadDir(intr fs.Intr) ([]fuse.Dirent, fuse.Error) {
|
|||||||
// Node is the core object representing a filesystem tree node.
|
// Node is the core object representing a filesystem tree node.
|
||||||
type Node struct {
|
type Node struct {
|
||||||
nsRoot *Node
|
nsRoot *Node
|
||||||
|
name string
|
||||||
|
|
||||||
// Private keys held by nodes at the root of a keyspace
|
// Private keys held by nodes at the root of a keyspace
|
||||||
key ci.PrivKey
|
key ci.PrivKey
|
||||||
@ -192,6 +193,7 @@ type Node struct {
|
|||||||
fd *mdag.DagReader
|
fd *mdag.DagReader
|
||||||
cached *mdag.PBData
|
cached *mdag.PBData
|
||||||
|
|
||||||
|
// For writing
|
||||||
dataBuf *bytes.Buffer
|
dataBuf *bytes.Buffer
|
||||||
changed bool
|
changed bool
|
||||||
}
|
}
|
||||||
@ -227,25 +229,30 @@ func (s *Node) Attr() fuse.Attr {
|
|||||||
|
|
||||||
// Lookup performs a lookup under this node.
|
// Lookup performs a lookup under this node.
|
||||||
func (s *Node) Lookup(name string, intr fs.Intr) (fs.Node, fuse.Error) {
|
func (s *Node) Lookup(name string, intr fs.Intr) (fs.Node, fuse.Error) {
|
||||||
log.Debug("ipns: node Lookup '%s'", name)
|
log.Debug("ipns: node[%s] Lookup '%s' [intr= %s]", s.name, name, intr.String())
|
||||||
nd, err := s.Ipfs.Resolver.ResolveLinks(s.Nd, []string{name})
|
nd, err := s.Ipfs.Resolver.ResolveLinks(s.Nd, []string{name})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// todo: make this error more versatile.
|
// todo: make this error more versatile.
|
||||||
return nil, fuse.ENOENT
|
return nil, fuse.ENOENT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return s.makeChild(name, nd), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *Node) makeChild(name string, node *mdag.Node) *Node {
|
||||||
child := &Node{
|
child := &Node{
|
||||||
Ipfs: s.Ipfs,
|
Ipfs: n.Ipfs,
|
||||||
Nd: nd,
|
Nd: node,
|
||||||
|
name: name,
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.nsRoot == nil {
|
if n.nsRoot == nil {
|
||||||
child.nsRoot = s
|
child.nsRoot = n
|
||||||
} else {
|
} else {
|
||||||
child.nsRoot = s.nsRoot
|
child.nsRoot = n.nsRoot
|
||||||
}
|
}
|
||||||
|
|
||||||
return child, nil
|
return child
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadDir reads the link structure as directory entries
|
// ReadDir reads the link structure as directory entries
|
||||||
@ -358,6 +365,55 @@ func (n *Node) Fsync(req *fuse.FsyncRequest, intr fs.Intr) fuse.Error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *Node) Mkdir(req *fuse.MkdirRequest, intr fs.Intr) (fs.Node, fuse.Error) {
|
||||||
|
log.Debug("Got mkdir request!")
|
||||||
|
dagnd := new(mdag.Node)
|
||||||
|
dagnd.Data = mdag.FolderPBData()
|
||||||
|
n.Nd.AddNodeLink(req.Name, dagnd)
|
||||||
|
n.changed = true
|
||||||
|
|
||||||
|
child := &Node{
|
||||||
|
Ipfs: n.Ipfs,
|
||||||
|
Nd: dagnd,
|
||||||
|
}
|
||||||
|
|
||||||
|
if n.nsRoot == nil {
|
||||||
|
child.nsRoot = n
|
||||||
|
} else {
|
||||||
|
child.nsRoot = n.nsRoot
|
||||||
|
}
|
||||||
|
|
||||||
|
return child, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *Node) Mknod(req *fuse.MknodRequest, intr fs.Intr) (fs.Node, fuse.Error) {
|
||||||
|
log.Debug("Got mknod request!")
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
func (n *Node) Open(req *fuse.OpenRequest, resp *fuse.OpenResponse, intr fs.Intr) (fs.Handle, fuse.Error) {
|
||||||
|
log.Debug("[%s] Received open request! flags = %s", n.name, req.Flags.String())
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *Node) Create(req *fuse.CreateRequest, resp *fuse.CreateResponse, intr fs.Intr) (fs.Node, fs.Handle, fuse.Error) {
|
||||||
|
log.Debug("Got create request!")
|
||||||
|
nd := new(mdag.Node)
|
||||||
|
nd.Data = mdag.FilePBData(nil)
|
||||||
|
child := n.makeChild(req.Name, nd)
|
||||||
|
|
||||||
|
err := n.Nd.AddNodeLink(req.Name, nd)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Error adding child to node: %s", err)
|
||||||
|
return nil, nil, fuse.ENOENT
|
||||||
|
}
|
||||||
|
return child, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *Node) Remove(req *fuse.RemoveRequest, intr fs.Intr) fuse.Error {
|
||||||
|
log.Debug("Got Remove request!")
|
||||||
|
return fuse.EIO
|
||||||
|
}
|
||||||
|
|
||||||
// Mount mounts an IpfsNode instance at a particular path. It
|
// Mount mounts an IpfsNode instance at a particular path. It
|
||||||
// serves until the process receives exit signals (to Unmount).
|
// serves until the process receives exit signals (to Unmount).
|
||||||
func Mount(ipfs *core.IpfsNode, fpath string, ipfspath string) error {
|
func Mount(ipfs *core.IpfsNode, fpath string, ipfspath string) error {
|
||||||
|
Reference in New Issue
Block a user