本文整理匯總了Golang中github.com/hanwen/go-fuse/fuse/nodefs.NewDataFile函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewDataFile函數的具體用法?Golang NewDataFile怎麽用?Golang NewDataFile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewDataFile函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
示例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
}
示例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
}
示例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
}
示例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
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}