Exemple #1
0
func (d *DIR) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {

	dirDirs := []fuse.Dirent{}

	log.WithFields(log.Fields{"Dir": d.Entry.Name, "Prefix": d.Entry.Prefix}).Debug("ReadDirAll: ")

	d.RData.lock.RLock()
	dirTreeNode, err := dirTree.Lookup(d.RData.Root, d.Entry.Prefix, d.Entry.Name)
	tmp := *dirTreeNode
	d.RData.lock.RUnlock()

	if err != nil {
		log.WithFields(log.Fields{"Name": d.Entry.Name, "Error": err}).Error("ReadDirAll: dirTree lookup failed")
		return nil, fuse.ENOENT
	}

	for i := 0; i < dirTree.NumKids(&tmp); i++ {
		k, _ := dirTree.GetKid(&tmp, i)
		ent := k.Entry
		t := fuse.DT_Unknown
		if ent.IsDir {
			t = fuse.DT_Dir
		} else {
			t = fuse.DT_File
		}
		dirDirs = append(dirDirs, fuse.Dirent{Inode: 0, Type: t, Name: ent.Name})
	}

	return dirDirs, nil
}
Exemple #2
0
func (d *DIR) strLookup(ctx context.Context, Name string) (fs.Node, error) {

	var dirPrefix string
	if d.Entry.Prefix != "" {
		dirPrefix = d.Entry.Prefix + "/" + d.Entry.Name
	} else {
		dirPrefix = d.Entry.Name
	}

	d.RData.lock.RLock()
	defer d.RData.lock.RUnlock()

	log.WithFields(log.Fields{"Entry": Name, "Dir Prefix": dirPrefix}).Debug("dirTree Lookup: ")

	dirTreeNode, err := dirTree.Lookup(d.RData.Root, dirPrefix, Name)
	if err != nil {
		log.WithFields(log.Fields{"Name": Name, "Error": err}).Error("Lookup: dirTree lookup failed")
		return nil, fuse.ENOENT
	}

	entry := dirTreeNode.Entry

	if entry.IsDir {
		return &DIR{Acc: d.Acc,
			RData:     d.RData,
			Entry:     entry,
			remoteDir: d.remoteDir + "/" + Name,
			cacheDir:  d.cacheDir + "/" + Name}, nil
	}

	return &FILE{Acc: d.Acc,
		RData:      d.RData,
		Entry:      entry,
		remoteName: d.remoteDir + "/" + Name,
		cacheName:  d.cacheDir + "/" + Name,
		h:          nil}, nil
}