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

Golang pathfs.FileSystem类代码示例

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

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



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

示例1: TestSimpleFile

func (s *fuseTestSuite) TestSimpleFile() {
	datasetName := "TestSimpleFile"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	file, code := testfs.Create("coconut", uint32(os.O_CREATE|os.O_RDWR), 0644, nil)
	assert.Equal(s.T(), fuse.OK, code)
	n, code := file.Write([]byte("Lime!"), 0)
	assert.Equal(s.T(), uint32(5), n)
	assertAttr(s, testfs, "coconut", 0644|fuse.S_IFREG, 5)

	data := make([]byte, 5)
	rr, code := file.Read(data, 0)
	assert.Equal(s.T(), fuse.OK, code)
	assert.Equal(s.T(), 5, rr.Size())
	assert.Equal(s.T(), "Lime!", string(data))

	code = testfs.Truncate("coconut", 4, nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "coconut", 0644|fuse.S_IFREG, 4)
	rr, code = file.Read(data, 0)
	assert.Equal(s.T(), fuse.OK, code)
	assert.Equal(s.T(), 4, rr.Size())
	assert.Equal(s.T(), "Lime!", string(data))
}
开发者ID:Richardphp,项目名称:noms,代码行数:28,代码来源:rw_test.go


示例2: getAttr

func getAttr(fs pathfs.FileSystem, name string) *attrResponse {
	a, code := fs.GetAttr(name, nil)
	return &attrResponse{
		Attr:   a,
		Status: code,
	}
}
开发者ID:rfjakob,项目名称:go-fuse,代码行数:7,代码来源:cachingfs.go


示例3: readLink

func readLink(fs pathfs.FileSystem, name string) *linkResponse {
	a, code := fs.Readlink(name, nil)
	return &linkResponse{
		linkContent: a,
		Status:      code,
	}
}
开发者ID:rfjakob,项目名称:go-fuse,代码行数:7,代码来源:cachingfs.go


示例4: getXAttr

func getXAttr(fs pathfs.FileSystem, nameAttr string) *xattrResponse {
	ns := strings.SplitN(nameAttr, _XATTRSEP, 2)
	a, code := fs.GetXAttr(ns[0], ns[1], nil)
	return &xattrResponse{
		data:   a,
		Status: code,
	}
}
开发者ID:rfjakob,项目名称:go-fuse,代码行数:8,代码来源:cachingfs.go


示例5: assertAttr

func assertAttr(s *fuseTestSuite, fs pathfs.FileSystem, path string, mode uint32, size uint64) {
	attr, code := fs.GetAttr(path, nil)
	assert.Equal(s.T(), fuse.OK, code)
	if code == fuse.OK {
		assert.Equal(s.T(), mode, attr.Mode)
		assert.Equal(s.T(), size, attr.Size)
	}
}
开发者ID:Richardphp,项目名称:noms,代码行数:8,代码来源:basics_test.go


示例6: readDir

func readDir(fs pathfs.FileSystem, name string) *dirResponse {
	origStream, code := fs.OpenDir(name, nil)

	r := &dirResponse{nil, code}
	if !code.Ok() {
		return r
	}
	r.entries = origStream
	return r
}
开发者ID:rfjakob,项目名称:go-fuse,代码行数:10,代码来源:cachingfs.go


示例7: TestFile

func (s *fuseTestSuite) TestFile() {
	datasetName := "TestFile"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	_, code := testfs.Create("pokemon.go", uint32(os.O_CREATE)|uint32(os.O_WRONLY), 0644, nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "pokemon.go", 0644|fuse.S_IFREG, 0)
}
开发者ID:Richardphp,项目名称:noms,代码行数:12,代码来源:basics_test.go


示例8: TestDir

func (s *fuseTestSuite) TestDir() {
	datasetName := "TestDir"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	code := testfs.Mkdir("noms", 0777, nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "noms", 0777|fuse.S_IFDIR, 0)
}
开发者ID:Richardphp,项目名称:noms,代码行数:12,代码来源:basics_test.go


示例9: TestSymlink

func (s *fuseTestSuite) TestSymlink() {
	datasetName := "TestSymlink"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	code := testfs.Symlink("there", "here", nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "here", 0755|fuse.S_IFLNK, 0)
	value, code := testfs.Readlink("here", nil)
	assert.Equal(s.T(), fuse.OK, code)
	assert.Equal(s.T(), "there", value)
}
开发者ID:Richardphp,项目名称:noms,代码行数:15,代码来源:basics_test.go


示例10: TestUnlink

func (s *fuseTestSuite) TestUnlink() {
	datasetName := "TestUnlink"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	_, code := testfs.Create("dilma", uint32(os.O_CREATE)|uint32(os.O_WRONLY), 0755, nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "", 0777|fuse.S_IFDIR, 1) // 1 means it's there
	code = testfs.Unlink("dilma", nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "", 0777|fuse.S_IFDIR, 0) // 0 means no entries
}
开发者ID:Richardphp,项目名称:noms,代码行数:15,代码来源:basics_test.go


示例11: TestRmdir

func (s *fuseTestSuite) TestRmdir() {
	datasetName := "TestRmdir"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	code := testfs.Mkdir("wikileaks", 0755, nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "", 0777|fuse.S_IFDIR, 1) // 1 means it's there
	code = testfs.Rmdir("wikileaks", nil)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "", 0777|fuse.S_IFDIR, 0) // 0 means no entries
}
开发者ID:Richardphp,项目名称:noms,代码行数:15,代码来源:basics_test.go


示例12: findDir

func findDir(fs pathfs.FileSystem, path string, delimiter string) []string {
	ents, _ := fs.OpenDir(path, nil)
	ret := make([]string, 0)
	for _, ent := range ents {
		child := path + delimiter + ent.Name
		attr, _ := fs.GetAttr(child, nil)
		if attr.Mode&fuse.S_IFDIR != 0 {
			ret = append(ret, child+"/")
			ret = append(ret, findDir(fs, child, "/")...)
		} else {
			ret = append(ret, child)
		}
	}

	return ret
}
开发者ID:Richardphp,项目名称:noms,代码行数:16,代码来源:dir_test.go


示例13: NewMemUnionFs

// NewMemUnionFs instantiates a new union file system.  Calling this
// will access the root of the supplied R/O filesystem.
func NewMemUnionFs(backingStore string, roFs pathfs.FileSystem) (*MemUnionFs, error) {
	me := &MemUnionFs{
		deleted:      make(map[string]bool),
		backingStore: backingStore,
		readonly:     roFs,
	}

	me.root = me.newNode(true)
	fi, code := roFs.GetAttr("", nil)
	if !code.Ok() {
		return nil, fmt.Errorf("GetAttr(\"\") for R/O returned %v", code)
	}

	me.root.info = *fi
	me.cond = sync.NewCond(&me.mutex)

	return me, nil
}
开发者ID:hanwen,项目名称:termite,代码行数:20,代码来源:memunionfs.go


示例14: newDirnameMap

// newDirnameMap reads the contents of the given directory. On error,
// returns a nil map. This forces reloads in the dirCache until we
// succeed.
func newDirnameMap(fs pathfs.FileSystem, dir string) map[string]bool {
	stream, code := fs.OpenDir(dir, nil)
	if code == fuse.ENOENT {
		// The directory not existing is not an error.
		return map[string]bool{}
	}

	if !code.Ok() {
		return nil
	}

	result := make(map[string]bool)
	for _, e := range stream {
		if e.Mode&fuse.S_IFREG != 0 {
			result[e.Name] = true
		}
	}
	return result
}
开发者ID:Richardphp,项目名称:noms,代码行数:22,代码来源:dircache.go


示例15: TestDirError

func (s *fuseTestSuite) TestDirError() {
	datasetName := "TestDirError"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	code := testfs.Mkdir("foo/bar", 0755, nil)
	assert.Equal(s.T(), fuse.ENOENT, code)
	_, code = testfs.Create("foo", uint32(os.O_CREATE)|uint32(os.O_WRONLY), 0644, nil)
	assert.Equal(s.T(), fuse.OK, code)
	code = testfs.Mkdir("foo/bar", 0755, nil)
	assert.Equal(s.T(), fuse.ENOTDIR, code)

	_, code = testfs.OpenDir("foo", nil)
	assert.Equal(s.T(), fuse.ENOTDIR, code)
}
开发者ID:Richardphp,项目名称:noms,代码行数:18,代码来源:dir_test.go


示例16: TestHierarchy

func (s *fuseTestSuite) TestHierarchy() {
	datasetName := "TestHierarchy"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	hierarchy := []string{
		"bin/",
		"bin/sh",
		"usr/",
		"usr/bin/",
		"usr/bin/cat",
		"usr/bin/bash",
		"usr/lib/",
		"usr/lib/libc.so.1",
		"usr/dict/",
		"usr/dict/words",
		"usr/dict/words2",
	}

	for _, path := range hierarchy {
		if ll := len(path); path[ll-1] == '/' {
			code := testfs.Mkdir(path[:ll-1], 0555, nil)
			assert.Equal(s.T(), fuse.OK, code)
		} else {
			_, code := testfs.Create(path, uint32(os.O_CREATE)|uint32(os.O_WRONLY), 0444, nil)
			assert.Equal(s.T(), fuse.OK, code)
		}
	}

	h := find(testfs)

	sort.Strings(hierarchy)
	sort.Strings(h)

	assert.Equal(s.T(), hierarchy, h)
}
开发者ID:Richardphp,项目名称:noms,代码行数:39,代码来源:dir_test.go


示例17: TestMultipleOpens

func (s *fuseTestSuite) TestMultipleOpens() {
	datasetName := "TestMultipleOpens"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	file1, code := testfs.Create("contend", uint32(os.O_CREATE|os.O_RDWR), 0644, nil)
	assert.Equal(s.T(), fuse.OK, code)

	file2, code := testfs.Open("contend", uint32(os.O_RDWR), nil)
	assert.Equal(s.T(), fuse.OK, code)

	file1.Write([]byte("abc contact"), 0)
	file2.Write([]byte("321"), 0)

	data := make([]byte, 11)
	rr, code := file1.Read(data, 0)
	assert.Equal(s.T(), fuse.OK, code)
	assert.Equal(s.T(), 11, rr.Size())
	assert.Equal(s.T(), "321 contact", string(data))
}
开发者ID:Richardphp,项目名称:noms,代码行数:23,代码来源:rw_test.go


示例18: TestBigFile

func (s *fuseTestSuite) TestBigFile() {
	datasetName := "TestBigFile"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	size := uint64(10 * 1024) // 10KB
	data := make([]byte, size)
	buf := bytes.NewBuffer(data)

	for uint64(buf.Len()) < size {
		buf.WriteString("All work and no play makes Jack a dull boy.\n")
	}

	file, code := testfs.Create("shining.txt", uint32(os.O_CREATE|os.O_RDWR), 0644, nil)
	assert.Equal(s.T(), fuse.OK, code)

	n, code := file.Write(buf.Bytes(), 0)
	assert.Equal(s.T(), uint32(size), n)
	assertAttr(s, testfs, "shining.txt", 0644|fuse.S_IFREG, size)
}
开发者ID:Richardphp,项目名称:noms,代码行数:23,代码来源:rw_test.go


示例19: TestOverwrite

func (s *fuseTestSuite) TestOverwrite() {
	datasetName := "TestOverwrite"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	file, code := testfs.Create("proclamation", uint32(os.O_CREATE|os.O_RDWR), 0644, nil)
	assert.Equal(s.T(), fuse.OK, code)

	n, code := file.Write([]byte("Four score and seven years ago..."), 0)
	assert.Equal(s.T(), uint32(33), n)
	assertAttr(s, testfs, "proclamation", 0644|fuse.S_IFREG, 33)
	n, code = file.Write([]byte("beers"), 21)
	assert.Equal(s.T(), uint32(5), n)
	assertAttr(s, testfs, "proclamation", 0644|fuse.S_IFREG, 33)

	data := make([]byte, 33)
	rr, code := file.Read(data, 0)
	assert.Equal(s.T(), fuse.OK, code)
	assert.Equal(s.T(), 33, rr.Size())
	assert.Equal(s.T(), "Four score and seven beers ago...", string(data))
}
开发者ID:Richardphp,项目名称:noms,代码行数:24,代码来源:rw_test.go


示例20: TestRenameWhileOpen

func (s *fuseTestSuite) TestRenameWhileOpen() {
	datasetName := "TestRenameWhileOpen"
	str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)

	var testfs pathfs.FileSystem

	start(str, func(fs pathfs.FileSystem) { testfs = fs })

	code := testfs.Mkdir("foo", 0755, nil)
	assert.Equal(s.T(), fuse.OK, code)
	code = testfs.Mkdir("foo/bar", 0755, nil)
	assert.Equal(s.T(), fuse.OK, code)
	file, code := testfs.Create("foo/bar/file.txt", uint32(os.O_CREATE)|uint32(os.O_WRONLY), 0644, nil)
	assert.Equal(s.T(), fuse.OK, code)

	// Validate renaming a file between opening it and writing to it.
	code = testfs.Rename("foo/bar/file.txt", "file.txt", nil)
	assert.Equal(s.T(), fuse.OK, code)

	n, code := file.Write([]byte("howdy!"), 0)
	assert.Equal(s.T(), uint32(6), n)
	assert.Equal(s.T(), fuse.OK, code)
	assertAttr(s, testfs, "file.txt", 0644|fuse.S_IFREG, 6)
}
开发者ID:Richardphp,项目名称:noms,代码行数:24,代码来源:dir_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang testutil.TempDir函数代码示例发布时间:2022-05-23
下一篇:
Golang pathfs.NewPathNodeFs函数代码示例发布时间: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