Commit e07b8e4e authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 25f5ea2f
......@@ -159,16 +159,29 @@ class tDB:
raise RuntimeError("wcsync #%d: wczhead (%s) != zhead (%s)" % (i, wchead, t._headv[i]))
t._wc_zheadv.append(wchead)
# path returns path joined with wcfs root
def path(t, path):
return os.path.join(t.wc.mountpoint, path)
# path returns path for object on wcfs.
# - str: wcfs root + obj;
# - Persistent: wcfs root + (head|@<rev>)/bigfile/obj
def path(t, obj, rev=None):
if isinstance(obj, Persistent):
head = "head/" if rev is None else ("@%s/" % h(rev))
obj = "%s/bigfile/%s" % (head, h(obj._p_oid))
rev = None
# fpath returns wcfs path for file corresponding to object ID.
# By default head/... is returned. If rev != None - @<rev>/... is returned.
# XXX -> filepath? fpath?
def filepath(t, obj, rev=None):
head = "head/" if rev is None else ("@%s/" % h(rev))
return t.path("%s/bigfile/%s" % (head, h(obj._p_oid)))
assert isinstance(obj, str)
assert rev is None # must not be used with str
return os.path.join(t.wc.mountpoint, obj)
# read reads file corresponding to obj on wcfs
def read(t, obj, rev=None):
path = t.path(obj, rev=rev)
return readfile(path)
# stat stats file corresponding to obj on wcfs
def stat(t, obj, rev=None):
path = t.path(obj, rev=rev)
return os.stat(path)
# XXX text ...
......@@ -188,13 +201,10 @@ def test_wcfs():
# lookup to non-BigFile - must be rejected
with raises(OSError) as exc:
os.stat(t.filepath(nonfile))
t.stat(nonfile)
assert exc.value.errno == EINVAL
# path to f under wcfs
fpath = t.filepath(f)
st = os.stat(fpath)
st = t.stat(f)
assert st.st_size == 0
assert st.st_mtime == tidtime(tid1)
......@@ -217,12 +227,12 @@ def test_wcfs():
# we wrote "hello world" after hole'th block, but size is always mutiple of blksize.
fsize = (hole + 1)*blksize
st = os.stat(fpath)
st = t.stat(f)
assert st.st_size == fsize
assert st.st_mtime == tidtime(t.head)
assert readfile(t.path("head/at")) == h(t.head)
data = readfile(fpath)
data = t.read(f)
assert len(data) == fsize
for i in range(hole):
assert data[i*blksize:(i+1)*blksize] == b'\0'*blksize
......@@ -248,12 +258,13 @@ def test_wcfs():
fsize1 = fsize
fsize = fsize1 + blksize # we added one more block
st = os.stat(fpath)
st = t.stat(f)
assert st.st_size == fsize
assert st.st_mtime == tidtime(t.head)
assert t.read("head/at") == h(t.head)
assert readfile(t.path("head/at")) == h(t.head)
data = readfile(fpath)
data = t.read(f)
assert len(data) == fsize
for i in range(hole):
assert data[i*blksize:(i+1)*blksize] == b'\0'*blksize
......@@ -274,6 +285,7 @@ def test_wcfs():
#assert st.st_mtime == tidtime(tcommit1) FIXME mtime for @revX -> = revX ?
#assert readfile(fpath + "/at") == h(tcommit1) XXX do we need it?
data = t.read(f, rev=tcommit1)
data = readfile(fpath1)
assert len(data) == fsize1
for i in range(hole):
......
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