Commit 68d7065a authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 638ae251
......@@ -254,6 +254,9 @@ import (
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/pkg/errors"
pickle "github.com/kisielk/og-rek" // XXX should be temp here?
)
// BigFileRoot represents "/bigfile"
......@@ -277,7 +280,7 @@ type BigFileHead struct {
nodefs.Node
x *BigFileX
data *BigFileData
data *BigFile
//at *BigFileAt
//inv *BigFileInvalidations
}
......@@ -286,7 +289,7 @@ type BigFileHead struct {
// XXX also @<tidX>/data ?
type BigFile struct {
nodefs.Node
head *BigFileHead
parent *BigFileHead // XXX name
topoid zodb.Oid // oid of ZBigFile
blksize int64 // ZBigFile.blksize XXX if it is changed - invalidate all? allowed to change?
......@@ -330,7 +333,7 @@ func NewBigFileHead(x *BigFileX) *BigFileHead {
func NewBigFile(head *BigFileHead) *BigFile {
return &BigFile{Node: nodefs.NewDefaultNode(), head: head}
return &BigFile{Node: nodefs.NewDefaultNode(), parent: head}
}
......@@ -343,19 +346,54 @@ func NewBigFile(head *BigFileHead) *BigFile {
func (br *BigFileRoot) Mkdir(name string, mode uint32, _ *fuse.Context) (*nodefs.Inode, fuse.Status) {
oid, err := zodb.ParseOid(name)
if err != nil {
log.Printf("/bigfile: mkdir: non-oid: %q", name)
log.Printf("/bigfile: mkdir %q: not-oid", name)
return nil, fuse.EINVAL
}
// XXX ok to ignore mode?
br.mu.Lock()
defer br.mu.Unlock()
if _, already := br.tab[oid]; already {
return nil, fuse.Status(syscall.EEXIST)
}
br.mu.Unlock()
ctx := context.Background() // XXX ok?
buf, _, err := br.zstor.Load(ctx, zodb.Xid{Oid: oid, At: zodb.TidMax}) // FIXME At, use serial
if err != nil {
switch errors.Cause(err).(type) {
case *zodb.NoObjectError:
return nil, fuse.EINVAL
case *zodb.NoDataError:
return nil, fuse.EINVAL // XXX ok?
default:
log.Printf("/bigfile: mkdir %q: %s", name, err)
return nil, fuse.EIO
}
}
pybf, err := zodb.PyData(buf.Data).Decode()
if err != nil {
log.Printf("/bigfile: mkdir %q: %s", name, err)
return nil, fuse.EIO
}
// XXX -> pyclass.FullName() != "wendelin.bigfile.file_zodb" + ".ZBigFile"
pybfClass := pickle.Class{Module: "wendelin.bigfile.file_zodb", Name: ".ZBigFile"}
if pybf.PyClass != pybfClass {
return nil, fuse.EINVAL
}
// XXX other checks?
br.mu.Lock()
defer br.mu.Unlock()
// XXX recheck - maybe it was already created while we were not holding br.mu
bx := NewBigFileX(oid, br)
br.tab[oid] = bx
......@@ -390,11 +428,13 @@ func (br *BigFileRoot) Mkdir(name string, mode uint32, _ *fuse.Context) (*nodefs
// Read implements reading from /bigfile/<bigfileX>/head/data.
// XXX and from /bigfile/<bigfileX>/@<tidX>/data.
/*
func (bf *BigFile) Read(_ nodefs.File, dest []byte, off int64, _ fuse.Context) (fuse.ReadResult, fuse.Status) {
.at
.topoid
// XXX
}
*/
......
......@@ -28,6 +28,7 @@ from persistent import Persistent
from persistent.timestamp import TimeStamp
import os, os.path, subprocess
from errno import EINVAL
from pytest import raises
testdb = None
......@@ -129,8 +130,18 @@ def test_bigfile_empty():
wc = wcfs.join(testzurl, autostart=True)
# path to bigfile/ under wcfs
bigpath = wc.mountpoint + "/bigfile"
# mkdir to non-BigFile - must be rejected
with raises(OSError) as exc:
os.mkdir("%s/%s" % (bigpath, last._p_oid.encode('hex')))
assert exc.value.errno == EINVAL
"""
# path to f under wcfs
fpath = "%s/bigfile/%s" % (wc.mountpoint, f._p_oid.encode('hex'))
fpath = "%s/%s" % (bigpath, f._p_oid.encode('hex'))
os.mkdir(fpath)
st = os.stat(fpath + "/head/data")
......@@ -139,6 +150,7 @@ def test_bigfile_empty():
assert readfile(fpath + "/head/at") == 'txn2'
# XXX head/at = last txn of whole db
"""
wc.close()
......
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