本文整理匯總了Golang中github.com/hanwen/go-fuse/fuse/pathfs.FileSystem.Create方法的典型用法代碼示例。如果您正苦於以下問題:Golang FileSystem.Create方法的具體用法?Golang FileSystem.Create怎麽用?Golang FileSystem.Create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hanwen/go-fuse/fuse/pathfs.FileSystem
的用法示例。
在下文中一共展示了FileSystem.Create方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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)
}
示例3: 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
}
示例4: 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)
}
示例5: TestFileInDir
func (s *fuseTestSuite) TestFileInDir() {
datasetName := "TestFile"
str := spec.CreateValueSpecString("ldb", s.LdbDir, datasetName)
var testfs pathfs.FileSystem
start(str, func(fs pathfs.FileSystem) { testfs = fs })
code := testfs.Mkdir("usr", 0555, nil)
assert.Equal(s.T(), fuse.OK, code)
code = testfs.Mkdir("usr/sbin", 0555, nil)
assert.Equal(s.T(), fuse.OK, code)
_, code = testfs.Create("usr/sbin/dtrace", uint32(os.O_CREATE)|uint32(os.O_WRONLY), 0555, nil)
assert.Equal(s.T(), fuse.OK, code)
assertAttr(s, testfs, "usr", 0555|fuse.S_IFDIR, 1)
assertAttr(s, testfs, "usr/sbin", 0555|fuse.S_IFDIR, 1)
assertAttr(s, testfs, "usr/sbin/dtrace", 0555|fuse.S_IFREG, 0)
}
示例6: 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)
}
示例7: 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)
}
示例8: 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))
}
示例9: 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)
}
示例10: 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))
}