本文整理匯總了Golang中github.com/hanwen/go-fuse/fuse/pathfs.FileSystem類的典型用法代碼示例。如果您正苦於以下問題:Golang FileSystem類的具體用法?Golang FileSystem怎麽用?Golang FileSystem使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FileSystem類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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))
}
示例2: getAttr
func getAttr(fs pathfs.FileSystem, name string) *attrResponse {
a, code := fs.GetAttr(name, nil)
return &attrResponse{
Attr: a,
Status: code,
}
}
示例3: readLink
func readLink(fs pathfs.FileSystem, name string) *linkResponse {
a, code := fs.Readlink(name, nil)
return &linkResponse{
linkContent: a,
Status: code,
}
}
示例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,
}
}
示例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)
}
}
示例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
}
示例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)
}
示例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)
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}