Ejemplo n.º 1
0
func (n *Node) Create(req *fuse.CreateRequest, resp *fuse.CreateResponse, intr fs.Intr) (fs.Node, fs.Handle, fuse.Error) {
	log.Debugf("Got create request: %s", req.Name)

	// New 'empty' file
	nd := &mdag.Node{Data: ft.FilePBData(nil, 0)}
	child := n.makeChild(req.Name, nd)

	nnode := n.Nd.Copy()

	err := nnode.AddNodeLink(req.Name, nd)
	if err != nil {
		log.Errorf("Error adding child to node: %s", err)
		return nil, nil, err
	}
	if n.parent != nil {
		err := n.parent.update(n.name, nnode)
		if err != nil {
			log.Criticalf("Error updating node: %s", err)
			// Can we panic, please?
			return nil, nil, err
		}
	}
	n.Nd = nnode
	n.wasChanged()

	return child, child, nil
}
Ejemplo n.º 2
0
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())
	//TODO: check open flags and truncate if necessary
	if req.Flags&fuse.OpenTruncate != 0 {
		log.Warning("Need to truncate file!")
		n.cached = nil
		n.Nd = &mdag.Node{Data: ft.FilePBData(nil, 0)}
	} else if req.Flags&fuse.OpenAppend != 0 {
		log.Warning("Need to append to file!")
	}
	return n, nil
}