Commit ac777ea5 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent a52fa604
......@@ -120,7 +120,7 @@ def join(zurl, autostart=_default_autostart()):
raise RuntimeError("wcfs: join %s: server not started" % zurl)
# start wcfs with telling it to automatically exit when there is no client activity.
return _start(zurl, "-autoexit")
return _start(zurl, "-autoexit", '-d')
# _start starts wcfs server for ZODB @ zurl.
......
......@@ -38,31 +38,42 @@ func asctx(fctx *fuse.Context) context.Context {
return context.Background()
}
// StaticFile is a Node for file with static data.
type StaticFile struct {
// NewStaticFile creates nodefs.Node for file with static data.
func NewStaticFile(data []byte) *SmallFile {
return NewSmallFile(func() []byte {
return data
})
}
// SmallFile is a nodefs.Node for file with dynamic, but always small, data.
type SmallFile struct {
nodefs.Node
data []byte
// readData gives whole file data
readData func() []byte
}
func NewStaticFile(data []byte) *StaticFile {
return &StaticFile{Node: nodefs.NewDefaultNode(), data: data}
func NewSmallFile(readData func() []byte) *SmallFile {
return &SmallFile{Node: nodefs.NewDefaultNode(), readData: readData}
}
func (f *StaticFile) GetAttr(out *fuse.Attr, _ nodefs.File, _ *fuse.Context) fuse.Status {
out.Size = uint64(len(f.data))
func (f *SmallFile) GetAttr(out *fuse.Attr, _ nodefs.File, _ *fuse.Context) fuse.Status {
data := f.readData()
out.Size = uint64(len(data))
out.Mode = fuse.S_IFREG | 0644
return fuse.OK
}
func (f *StaticFile) Read(_ nodefs.File, dest []byte, off int64, _ *fuse.Context) (fuse.ReadResult, fuse.Status) {
l := int64(len(f.data))
func (f *SmallFile) Read(_ nodefs.File, dest []byte, off int64, _ *fuse.Context) (fuse.ReadResult, fuse.Status) {
data := f.readData()
l := int64(len(data))
end := off + l
if end > l {
end = l
}
return fuse.ReadResultData(f.data[off:end]), fuse.OK
return fuse.ReadResultData(data[off:end]), fuse.OK
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment