예제 #1
0
파일: revelo.go 프로젝트: muthu-r/horcrux
func (d *DIR) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (fs.Node, fs.Handle, error) {

	// TODO: XXX
	//
	// - Check for req.Create flags!!
	//	- No need to handle O_EXCL - lookup takes care of it.
	// Anything else???
	// 	- How to use the req.Umask?
	//
	// log.Debug("Revelo:: Create called")

	acc := d.Acc
	entry := d.Entry

	var prefix string
	if entry.Prefix == "" {
		prefix = entry.Name
	} else {
		prefix = entry.Prefix + "/" + entry.Name
	}

	stat := horcrux.Stat{Mode: req.Mode, Size: 0, Uid: entry.Stat.Uid, Gid: entry.Stat.Gid}
	newEntry := horcrux.Entry{Name: req.Name, Prefix: prefix, IsDir: false, Stat: stat, NumChunks: 0}

	d.RData.lock.Lock()
	err := dirTree.Insert(d.RData.Root, newEntry)
	d.RData.lock.Unlock()

	if err != nil {
		log.WithFields(log.Fields{"newEntry": newEntry}).Error("Cannot insert to dir tree")
		return nil, nil, err
	}

	if err := saveMeta(d.RData); err != nil {
		log.Error("Revelo::Create: cannot update meta for create new file")
		return nil, nil, err
	}

	f := &FILE{Acc: acc,
		RData:      d.RData,
		Entry:      newEntry,
		cacheName:  d.cacheDir + "/" + req.Name,
		remoteName: ""}

	h := &HANDLE{Acc: acc, f: f, chunkSz: f.RData.Config.ChunkSize}
	f.h = h

	resp.LookupResponse.Attr = fuse.Attr{Mode: stat.Mode,
		Size: uint64(stat.Size),
		Uid:  stat.Uid,
		Gid:  stat.Gid}

	// XXX Populate resp.OpenResponse.Flags properly
	// resp.OpenResponse.Flags = ???

	//XXX check the return params with fuse
	return f, h, nil
}
예제 #2
0
파일: revelo.go 프로젝트: muthu-r/horcrux
func (d *DIR) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, error) {
	var prefix string

	entry := d.Entry
	if entry.Prefix == "" {
		prefix = entry.Name
	} else {
		prefix = entry.Prefix + "/" + entry.Name
	}

	//XXX Revisit size value - 4k for now.
	//XXX Should we use local Uid, Gid?
	stat := horcrux.Stat{Mode: req.Mode, Size: 4096, Uid: entry.Stat.Uid, Gid: entry.Stat.Gid}
	newEntry := horcrux.Entry{
		Name:      req.Name,
		Prefix:    prefix,
		IsDir:     true,
		Stat:      stat,
		NumChunks: 0}

	d.RData.lock.Lock()
	err := dirTree.Insert(d.RData.Root, newEntry)
	d.RData.lock.Unlock()

	if err != nil {
		log.WithFields(log.Fields{"newEntry": newEntry, "Error": err}).Error("Mkdir: Cannot insert new entry")
		return nil, err
	}

	if err := saveMeta(d.RData); err != nil {
		log.Error("Mkdir: save Meta  failed")
		// XXX May be later save meta will work... either way, it will recover after restart
		// d.RData.lock.Lock()
		// dirTree.Delete(d.RData.Root, prefix, req.Name)
		// d.RData.lock.Unlock()
		return nil, err
	}

	newD := &DIR{Acc: d.Acc,
		RData:     d.RData,
		Entry:     newEntry,
		cacheDir:  d.cacheDir + "/" + req.Name,
		remoteDir: ""}

	return newD, nil
}