• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang nodefs.NewDataFile函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/hanwen/go-fuse/fuse/nodefs.NewDataFile函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDataFile函数的具体用法?Golang NewDataFile怎么用?Golang NewDataFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewDataFile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Open

func (gf *GistFs) Open(n string, _ uint32, c *fuse.Context) (nodefs.File, fuse.Status) {
	if gf.files == nil {
		log.Println("Nil map. Files have not been queried yet.")
		return nil, fuse.ENOENT
	}

	if f, ok := gf.files[n]; ok {

		if f.contents != nil {
			//Cached copy
			return nodefs.NewDataFile(f.contents), fuse.OK
		}

		res, err := http.Get(f.RawUrl)
		defer res.Body.Close()
		if err != nil {
			log.Println(err)
			return nil, fuse.ENOENT
		}

		bs, err := ioutil.ReadAll(res.Body)
		if err != nil {
			log.Println(err)
			return nil, fuse.ENOENT
		}

		f.contents = bs

		return nodefs.NewDataFile(bs), fuse.OK
	}
	return nil, fuse.ENOENT
}
开发者ID:andrewstuart,项目名称:gistfs,代码行数:32,代码来源:main.go


示例2: Open

func (vfs FuseVfs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	log.Infof(2, "BEGIN Open(%v)", name)
	defer log.Infof(2, "END Open(%v)", name)

	switch name {
	case filepath.Join(queriesDir, helpFilename):
		return nodefs.NewDataFile([]byte(queryDirHelp)), fuse.OK
	case filepath.Join(tagsDir, helpFilename):
		return nodefs.NewDataFile([]byte(tagsDirHelp)), fuse.OK
	}

	return nil, fuse.ENOSYS
}
开发者ID:logtcn,项目名称:TMSU,代码行数:13,代码来源:fusevfs.go


示例3: Open

// Open is a FUSE function where an in-memory open file struct is constructed.
func (f *fs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	var file nodefs.File
	switch {
	case name == "":
		return nil, EISDIR
	case name == "secret":
		return nil, EISDIR
	default:
		s, err := f.client.Logical().Read(name)
		if err != nil {
			return nil, fuse.ENOENT
		}

		if s == nil || s.Data == nil {
			return nil, fuse.ENOENT
		}

		file = nodefs.NewDataFile([]byte(s.Data["value"].(string)))
	}

	if file != nil {
		file = nodefs.NewReadOnlyFile(file)
		return file, fuse.OK
	}
	return nil, fuse.ENOENT
}
开发者ID:pshouse,项目名称:global-hack-day-3,代码行数:27,代码来源:fs.go


示例4: Open

// Open is a FUSE function where an in-memory open file struct is constructed.
func (f *fs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	log.Printf("Open '%s'\n", name)
	var file nodefs.File
	switch {
	case name == "":
		return nil, EISDIR
	case name == "secret" || name == "sys":
		return nil, EISDIR
	case strings.HasPrefix(name, "secret/"):
		fmt.Println("got here")
		s, err := f.client.Logical().Read(name)
		if err != nil {
			log.Println(err)
			return nil, fuse.ENOENT
		}

		if s == nil || s.Data == nil {
			return nil, fuse.ENOENT
		}

		file = nodefs.NewDataFile([]byte(s.Data["value"].(string) + "\n"))
	}

	if file != nil {
		file = nodefs.NewReadOnlyFile(file)
		return file, fuse.OK
	}
	return nil, fuse.ENOENT
}
开发者ID:ChrisMcKenzie,项目名称:docker-volume-vault,代码行数:30,代码来源:fs.go


示例5: Open

// Open returns a datafile representing the HTTP response body
func (fs *MetadataFs) Open(name string, flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	url := fs.Endpoint + name

	log.Printf("[DEBUG] issuing HTTP GET to AWS metadata API for path: '%s'", url)
	resp, err := fs.Client.Get(url)
	if err != nil {
		log.Printf("[ERROR] failed to query AWS metadata API: %s", err)
		return nil, fuse.EIO
	}

	log.Printf("[DEBUG] got %d from AWS metadata API for path %s", resp.StatusCode, url)
	switch resp.StatusCode {
	case http.StatusNotFound:
		return nil, fuse.ENOENT
	case http.StatusOK:
		body, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			log.Printf("[ERROR] failed to query AWS metadata API: %s", err)
			return nil, fuse.EIO
		}

		return nodefs.NewDataFile(body), fuse.OK
	default:
		log.Printf("[ERROR] unknown HTTP status code from AWS metadata API: %d", resp.StatusCode)
		return nil, fuse.EIO
	}
}
开发者ID:jszwedko,项目名称:ec2-metadatafs,代码行数:28,代码来源:metadatafs.go


示例6: Open

func (me *P9Fs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {

	var user go9p.User
	var err error
	var c *clnt.Clnt
	var file *clnt.File
	var f []byte

	user = go9p.OsUsers.Uid2User(os.Geteuid())
	clnt.DefaultDebuglevel = 0
	c, err = clnt.Mount("tcp", address, "", user)
	if err != nil {
		goto error
	}

	file, err = c.FOpen("/tmp/anaconda-post.log", go9p.OREAD)
	if err != nil {
		goto error
	}
	defer file.Close()
	f, err = ioutil.ReadAll(file)

	if err != nil && err != io.EOF {
		goto error
	}

	return nodefs.NewDataFile(f), fuse.OK

error:
	log.Println("Error", err)
	return nil, fuse.EPERM
}
开发者ID:waterytowers,项目名称:global-hack-day-3,代码行数:32,代码来源:main.go


示例7: Open

func (n *memNode) Open(flags uint32, context *fuse.Context) (fuseFile nodefs.File, code fuse.Status) {
	if flags&fuse.O_ANYWRITE != 0 {
		return nil, fuse.EPERM
	}

	return nodefs.NewDataFile(n.file.Data()), fuse.OK
}
开发者ID:rfjakob,项目名称:go-fuse,代码行数:7,代码来源:memtree.go


示例8: Open

func (me *HelloFs) Open(name string, flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	if name != "file.txt" {
		return nil, fuse.ENOENT
	}
	if flags&fuse.O_ANYWRITE != 0 {
		return nil, fuse.EPERM
	}
	return nodefs.NewDataFile([]byte(name)), fuse.OK
}
开发者ID:rfjakob,项目名称:go-fuse,代码行数:9,代码来源:main.go


示例9: Open

func (me *DropboxFs) Open(name string, flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	path := get_path(name)
	log.Printf("Open: '%s'\n", name)
	if flags&fuse.O_ANYWRITE != 0 {
		return nil, fuse.EPERM
	}
	// XXX: errors!
	res, _ := GetFile(path)
	return nodefs.NewDataFile(res), fuse.OK
}
开发者ID:sgodbold,项目名称:dropbox-mnt-go,代码行数:10,代码来源:fs.go


示例10: Open

func (me *RdiffFs) Open(name string, flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {

	// fmt.Println("Open", name)
	// if name != "file.txt" {
	// 	return nil, fuse.ENOENT
	// }
	// if flags&fuse.O_ANYWRITE != 0 {
	// 	return nil, fuse.EPERM
	// }
	return nodefs.NewDataFile([]byte(name)), fuse.OK
}
开发者ID:jostillmanns,项目名称:Rdiff-Backup-Tools,代码行数:11,代码来源:fuserdiff.go


示例11: Open

func (fs *nonseekFs) Open(name string, flags uint32, context *fuse.Context) (fuseFile nodefs.File, status fuse.Status) {
	if name != "file" {
		return nil, fuse.ENOENT
	}

	data := bytes.Repeat([]byte{42}, fs.Length)
	f := nodefs.NewDataFile(data)
	return &nodefs.WithFlags{
		File:      f,
		FuseFlags: fuse.FOPEN_NONSEEKABLE,
	}, fuse.OK
}
开发者ID:jszwedko,项目名称:ec2-metadatafs,代码行数:12,代码来源:cache_test.go


示例12: Open

// Open is a FUSE function where an in-memory open file struct is constructed.
func (kwfs KeywhizFs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	kwfs.Debugf("Open called with '%v'", name)

	var file nodefs.File
	switch {
	case name == "", name == ".json", name == ".json/secret":
		return nil, EISDIR
	case name == ".version":
		file = nodefs.NewDataFile([]byte(VERSION))
	case name == ".clear_cache":
		file = nodefs.NewDevNullFile()
	case name == ".running":
		file = nodefs.NewDataFile(running())
	case name == ".json/secrets":
		data, ok := kwfs.Client.RawSecretList()
		if ok {
			file = nodefs.NewDataFile(data)
		}
	case strings.HasPrefix(name, ".json/secret/"):
		name = name[len(".json/secret/"):]
		data, ok := kwfs.Client.RawSecret(name)
		if ok {
			file = nodefs.NewDataFile(data)
			kwfs.Infof("Access to %s by uid %d, with gid %d", name, context.Uid, context.Gid)
		}
	default:
		secret, ok := kwfs.Cache.Secret(name)
		if ok {
			file = nodefs.NewDataFile(secret.Content)
			kwfs.Infof("Access to %s by uid %d, with gid %d", name, context.Uid, context.Gid)
		}
	}

	if file != nil {
		file = nodefs.NewReadOnlyFile(file)
		return file, fuse.OK
	}
	return nil, fuse.ENOENT
}
开发者ID:rxacevedo,项目名称:keywhiz-fs,代码行数:40,代码来源:fs.go


示例13: Create

func (fs *GrpcFs) Create(name string, flags uint32, mode uint32, ctx *fuse.Context) (nodefs.File, fuse.Status) {
	req := &pb.CreateRequest{
		Name:    name,
		Flags:   flags,
		Mode:    mode,
		Context: pbContext(ctx),
	}
	resp, err := fs.client.Create(context.Background(), req)
	if err != nil {
		return nil, fuse.ToStatus(err)
	}
	return nodefs.NewDataFile(resp.File.Data), resp.Status.Code
}
开发者ID:LK4D4,项目名称:grfuse,代码行数:13,代码来源:grpcfs.go


示例14: Open

func (fs *autoUnionFs) Open(path string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	if path == filepath.Join(_STATUS, _DEBUG) {
		if flags&fuse.O_ANYWRITE != 0 {
			return nil, fuse.EPERM
		}

		return nodefs.NewDataFile([]byte(fs.DebugData())), fuse.OK
	}
	if path == filepath.Join(_STATUS, _VERSION) {
		if flags&fuse.O_ANYWRITE != 0 {
			return nil, fuse.EPERM
		}
		return nodefs.NewDataFile([]byte(fs.options.Version)), fuse.OK
	}
	if path == filepath.Join(_CONFIG, _SCAN_CONFIG) {
		if flags&fuse.O_ANYWRITE != 0 {
			fs.updateKnownFses()
		}
		return nodefs.NewDevNullFile(), fuse.OK
	}
	return nil, fuse.ENOENT
}
开发者ID:rfjakob,项目名称:go-fuse,代码行数:22,代码来源:autounion.go


示例15: Open

func (gfs *GoMonitorFs) Open(name string, flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	if flags&fuse.O_ANYWRITE != 0 {
		return nil, fuse.EPERM
	}
	parts := strings.Split(name, string(os.PathSeparator))
	if source, ok := gfs.Sources[parts[0]]; ok {
		content, found := source.Contents(parts[1])
		if !found {
			return nil, fuse.EPERM
		}
		return nodefs.NewDataFile(content), fuse.OK
	}
	return nil, fuse.EPERM
}
开发者ID:jmptrader,项目名称:goinfo,代码行数:14,代码来源:gmfs.go


示例16: Open

func (fs *GrpcFs) Open(name string, flags uint32, ctx *fuse.Context) (nodefs.File, fuse.Status) {
	req := &pb.OpenRequest{
		Name:    name,
		Flags:   flags,
		Context: pbContext(ctx),
	}
	resp, err := fs.client.Open(context.Background(), req)
	if err != nil {
		return nil, fuse.ToStatus(err)
	}
	if resp.Status.Code != fuse.OK {
		return nil, resp.Status.Code
	}
	return nodefs.NewDataFile(resp.File.Data), fuse.OK
}
开发者ID:LK4D4,项目名称:grfuse,代码行数:15,代码来源:grpcfs.go


示例17: TestLoggingFile

func TestLoggingFile(t *testing.T) {
	var logOut bytes.Buffer
	cli.Log = &logrus.Logger{
		Out:       &logOut,
		Formatter: new(logrus.JSONFormatter),
		Level:     logrus.DebugLevel,
	}
	flags := 42

	file := newLoggingFile(nodefs.NewDataFile([]byte{}), "")
	code := file.Fsync(flags)
	assert.False(t, code.Ok())

	var output map[string]interface{}
	assert.NoError(t, json.Unmarshal(logOut.Bytes(), &output))

	assert.NotEmpty(t, output["status"])
	assert.Equal(t, "File Fsync", output["msg"])
	assert.True(t, output["duration_ms"].(float64) >= 0)
	assert.Equal(t, "[42]", output["args"])
	assert.NotEmpty(t, output["time"])
}
开发者ID:freakmac,项目名称:adbfs,代码行数:22,代码来源:util_test.go


示例18: Open

// Open returns a datafile representing the tag value
func (fs *TagsFs) Open(name string, flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	log.Printf("[DEBUG] issuing request to AWS API for tag: %s", name)

	resp, err := fs.Client.DescribeTags(&ec2.DescribeTagsInput{
		Filters: []*ec2.Filter{
			{Name: aws.String("key"), Values: []*string{aws.String(name)}},
			{Name: aws.String("resource-id"), Values: []*string{aws.String(fs.InstanceID)}},
		},
	})

	if err != nil {
		log.Printf("[ERROR] failed to query AWS API: %s", err)
		return nil, fuse.EIO
	}

	if len(resp.Tags) == 0 {
		log.Printf("[DEBUG] no tag found for %s", name)
		return nil, fuse.ENOENT
	}

	return nodefs.NewDataFile([]byte(*resp.Tags[0].Value)), fuse.OK
}
开发者ID:jszwedko,项目名称:ec2-metadatafs,代码行数:23,代码来源:tagsfs.go


示例19: Open

func (fs *KafkaRoFs) Open(name string, flags uint32,
	context *fuse.Context) (nodefs.File, fuse.Status) {
	parsed, err := fs.parseAndValidate(name)
	if err != nil {
		return nil, fuse.EIO
	}

	if !parsed.IsValid || parsed.Offset == -1 {
		return nil, fuse.ENOENT
	}

	if flags&fuse.O_ANYWRITE != 0 {
		return nil, fuse.EPERM
	}

	msgBytes, ferr := fs.getMessage(parsed.Topic, parsed.Partition, parsed.Offset)

	if ferr != fuse.OK {
		return nil, ferr
	}

	return nodefs.NewDataFile(msgBytes), fuse.OK
}
开发者ID:carriercomm,项目名称:kafkafs,代码行数:23,代码来源:kafkarofs.go


示例20: Create

func (fs *ElasticFs) Create(name string, flags uint32, mode uint32, context *fuse.Context) (fuseFile nodefs.File, code fuse.Status) {
	fmt.Printf("Create %s", name)
	return nodefs.NewDataFile([]byte(name)), fuse.OK
}
开发者ID:nickschuch,项目名称:fuse-elasticsearch,代码行数:4,代码来源:fs.go



注:本文中的github.com/hanwen/go-fuse/fuse/nodefs.NewDataFile函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang nodefs.NewDefaultFile函数代码示例发布时间:2022-05-23
下一篇:
Golang nodefs.MountRoot函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap