-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfuse_document.go
More file actions
60 lines (47 loc) · 1.08 KB
/
fuse_document.go
File metadata and controls
60 lines (47 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"encoding/json"
"time"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"labix.org/v2/mgo/bson"
)
// DocumentFile implements both Node and Handle for a document from a collection.
type DocumentFile struct {
coll string
Id bson.ObjectId `bson:"_id"`
Dirent fuse.Dirent
Fattr fuse.Attr
}
func (d DocumentFile) Attr() fuse.Attr {
slog.Noticef("DocumentFile.Attr() for: %+v", d)
now := time.Now()
return fuse.Attr{
Mode: 0400,
Size: 42,
Ctime: now,
Atime: now,
Mtime: now,
}
}
func (d DocumentFile) Lookup(fname string, intr fs.Intr) (fs.Node, fuse.Error) {
slog.Noticef("DocumentFile[%s].Lookup(): %s\n", d.coll, fname)
return nil, fuse.ENOENT
}
func (d DocumentFile) ReadAll(intr fs.Intr) ([]byte, fuse.Error) {
slog.Noticef("DocumentFile[%s].ReadAll(): %s\n", d.coll, d.Id)
db, s := getDb()
defer s.Close()
var f interface{}
err := db.C(d.coll).FindId(d.Id).One(&f)
if err != nil {
slog.Error(err)
return nil, fuse.EIO
}
buf, err := json.MarshalIndent(f, "", " ")
if err != nil {
slog.Error(err)
return nil, fuse.EIO
}
return buf, nil
}