Пример #1
0
func (gf *GistFs) OpenDir(n string, c *fuse.Context) ([]fuse.DirEntry, fuse.Status) {

	dirs := make([]fuse.DirEntry, 0)
	if gf.files != nil && n == "" {
		for _, f := range gf.files {
			d := fuse.DirEntry{Name: f.Name, Mode: fuse.S_IFREG | 0440}
			if f.isDir {
				d.Mode = fuse.S_IFDIR | 0550
			}
			dirs = append(dirs, d)
		}
		return dirs, fuse.OK
	}

	gf.files = make(map[string]File)

	u := gf.user
	if n != "" {
		u = n
	}

	gists, err := getGists(u)
	if err != nil {
		log.Println(err)
		return nil, fuse.ENOENT
	}
	for _, g := range gists {
		for _, f := range g.Files {
			gf.files[n+f.Name] = f
			dirs = append(dirs, fuse.DirEntry{Name: f.Name, Mode: fuse.S_IFREG | 0440})
		}
	}
	return dirs, fuse.OK
}
Пример #2
0
func (fs *loopbackFileSystem) OpenDir(name string, context *fuse.Context) (stream []fuse.DirEntry, status fuse.Status) {
	// What other ways beyond O_RDONLY are there to open
	// directories?
	f, err := os.Open(fs.GetPath(name))
	if err != nil {
		return nil, fuse.ToStatus(err)
	}
	want := 500
	output := make([]fuse.DirEntry, 0, want)
	for {
		infos, err := f.Readdir(want)
		for i := range infos {
			n := infos[i].Name()
			d := fuse.DirEntry{
				Name: n,
			}
			if s := fuse.ToStatT(infos[i]); s != nil {
				d.Mode = uint32(s.Mode)
			} else {
				log.Printf("ReadDir entry %q for %q has no stat info", n, name)
			}
			output = append(output, d)
		}
		if len(infos) < want || err == io.EOF {
			break
		}
		if err != nil {
			log.Println("Readdir() returned err:", err)
			break
		}
	}
	f.Close()

	return output, fuse.OK
}
Пример #3
0
func (me *DropboxFs) OpenDir(name string, context *fuse.Context) (c []fuse.DirEntry, code fuse.Status) {
	path := get_path(name)
	log.Printf("OpenDir: '%s'\n", name)

	data, err := Cache.Metadata.Get(path)
	entry := fuse.DirEntry{}

	if data.IsDir && err == nil {
		for _, path := range data.Contents {
			entry.Name = NameFromPath(path)
			c = append(c, entry)
		}
		return c, fuse.OK
	}
	return nil, fuse.ENOENT
}
Пример #4
0
func (fs *KakigooriFileSystem) OpenDir(name string, context *fuse.Context) (stream []fuse.DirEntry, status fuse.Status) {
	fullPath := fs.GetPath(name)
	f, err := os.Open(fullPath)
	if err != nil {
		return nil, fuse.ToStatus(err)
	}
	want := 500
	output := make([]fuse.DirEntry, 0, want)
	for {
		infos, err := f.Readdir(want)
		for i := range infos {
			// workaround for https://code.google.com/p/go/issues/detail?id=5960
			if infos[i] == nil {
				continue
			}
			n := infos[i].Name()
			d := fuse.DirEntry{
				Name: n,
			}
			if s := fuse.ToStatT(infos[i]); s != nil {
				d.Mode = uint32(s.Mode)
			} else {
				log.Printf("ReadDir entry %q for %q has no stat info", n, name)
			}
			output = append(output, d)
		}
		if len(infos) < want || err == io.EOF {
			break
		}
		if err != nil {
			log.Println("Readdir() returned err:", err)
			break
		}
	}
	f.Close()
	go event.Notify(event.OpenDir, fullPath)
	return output, fuse.OK
}
Пример #5
0
func (me *MultiZipFs) OpenDir(name string) (stream chan fuse.DirEntry, code fuse.Status) {
	me.lock.RLock()
	defer me.lock.RUnlock()

	// We don't use a goroutine, since we don't want to hold the
	// lock.
	stream = make(chan fuse.DirEntry,
		len(me.pendingZips)+len(me.zips)+2)

	submode := uint32(fuse.S_IFDIR | 0700)
	if name == "config" {
		submode = fuse.S_IFREG | 0600
	}

	for k, _ := range me.zips {
		var d fuse.DirEntry
		d.Name = k
		d.Mode = submode
		stream <- fuse.DirEntry(d)
	}
	for k, _ := range me.pendingZips {
		var d fuse.DirEntry
		d.Name = k
		d.Mode = submode
		stream <- fuse.DirEntry(d)
	}

	if name == "" {
		var d fuse.DirEntry
		d.Name = "config"
		d.Mode = fuse.S_IFDIR | 0700
		stream <- fuse.DirEntry(d)
	}

	close(stream)
	return stream, fuse.OK
}
Пример #6
0
func (fs *MultiZipFs) OpenDir(name string, context *fuse.Context) (stream []fuse.DirEntry, code fuse.Status) {
	fs.lock.RLock()
	defer fs.lock.RUnlock()

	stream = make([]fuse.DirEntry, 0, len(fs.zips)+2)
	if name == "" {
		var d fuse.DirEntry
		d.Name = "config"
		d.Mode = fuse.S_IFDIR | 0700
		stream = append(stream, fuse.DirEntry(d))
	}

	if name == "config" {
		for k := range fs.zips {
			var d fuse.DirEntry
			d.Name = k
			d.Mode = fuse.S_IFLNK
			stream = append(stream, fuse.DirEntry(d))
		}
	}

	return stream, fuse.OK
}
Пример #7
0
func (me *MultiZipFs) OpenDir(name string, context *fuse.Context) (stream chan fuse.DirEntry, code fuse.Status) {
	me.lock.RLock()
	defer me.lock.RUnlock()

	stream = make(chan fuse.DirEntry, len(me.zips)+2)
	if name == "" {
		var d fuse.DirEntry
		d.Name = "config"
		d.Mode = fuse.S_IFDIR | 0700
		stream <- fuse.DirEntry(d)
	}

	if name == "config" {
		for k, _ := range me.zips {
			var d fuse.DirEntry
			d.Name = k
			d.Mode = fuse.S_IFLNK
			stream <- fuse.DirEntry(d)
		}
	}

	close(stream)
	return stream, fuse.OK
}