mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 13:33:09 +00:00
fix several methods to handle LIT URIs correctly, rather than assuming that all filenodes are CHK URIs
This commit is contained in:
parent
53cf757be3
commit
ba7e14a870
@ -340,6 +340,11 @@ class ImmutableDirectoryNode:
|
||||
manifest.add(self.get_refresh_capability())
|
||||
|
||||
d = self._build_manifest_from_node(self, manifest)
|
||||
# LIT nodes have no refresh-capability: their data is stored inside
|
||||
# the URI itself, so there is no need to refresh anything. They
|
||||
# indicate this by returning None from their get_refresh_capability
|
||||
# method. We need to remove any such Nones from our set.
|
||||
d.addCallback(lambda res: manifest.discard(None))
|
||||
d.addCallback(lambda res: manifest)
|
||||
return d
|
||||
|
||||
@ -420,8 +425,11 @@ class FileNode:
|
||||
return cmp(self.uri, them.uri)
|
||||
|
||||
def get_refresh_capability(self):
|
||||
d = uri.unpack_uri(self.uri)
|
||||
return "CHK-REFRESH:%s" % idlib.b2a(d['storage_index'])
|
||||
t = uri.get_uri_type(self.uri)
|
||||
if t == "CHK":
|
||||
d = uri.unpack_uri(self.uri)
|
||||
return "CHK-REFRESH:%s" % idlib.b2a(d['storage_index'])
|
||||
return None
|
||||
|
||||
def download(self, target):
|
||||
downloader = self._client.getServiceNamed("downloader")
|
||||
|
@ -326,7 +326,8 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase):
|
||||
return d
|
||||
|
||||
def _do_publish_private(self, res):
|
||||
ut = upload.Data(self.data)
|
||||
self.smalldata = "sssh, very secret stuff"
|
||||
ut = upload.Data(self.smalldata)
|
||||
vdrive0 = self.clients[0].getServiceNamed("vdrive")
|
||||
d = vdrive0.get_node_at_path("~")
|
||||
d.addCallback(self.log, "GOT ~")
|
||||
@ -395,7 +396,7 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase):
|
||||
self.failUnless(IDirectoryNode.providedBy(dirnode)))
|
||||
d.addCallback(lambda res: get_path("~/personal/sekrit data"))
|
||||
d.addCallback(lambda filenode: filenode.download_to_data())
|
||||
d.addCallback(lambda data: self.failUnlessEqual(data, self.data))
|
||||
d.addCallback(lambda data: self.failUnlessEqual(data, self.smalldata))
|
||||
d.addCallback(lambda res: get_path("~/s2-rw"))
|
||||
d.addCallback(lambda dirnode: self.failUnless(dirnode.is_mutable()))
|
||||
d.addCallback(lambda res: get_path("~/s2-ro"))
|
||||
|
@ -9,6 +9,8 @@ class LIT(unittest.TestCase):
|
||||
u = uri.pack_lit(data)
|
||||
self.failUnlessEqual(uri.get_uri_type(u), "LIT")
|
||||
self.failUnlessEqual(uri.unpack_lit(u), data)
|
||||
self.failUnless(uri.is_filenode_uri(u))
|
||||
self.failUnlessEqual(uri.get_filenode_size(u), len(data))
|
||||
|
||||
def test_nonascii(self):
|
||||
data = "This contains \x00 and URI:LIT: and \n, oh my."
|
||||
@ -39,6 +41,9 @@ class CHK(unittest.TestCase):
|
||||
self.failUnlessEqual(d['total_shares'], total_shares)
|
||||
self.failUnlessEqual(d['size'], size)
|
||||
|
||||
self.failUnless(uri.is_filenode_uri(u))
|
||||
self.failUnlessEqual(uri.get_filenode_size(u), size)
|
||||
|
||||
class Extension(unittest.TestCase):
|
||||
def test_pack(self):
|
||||
data = {"stuff": "value",
|
||||
|
@ -180,7 +180,7 @@ class Web(unittest.TestCase):
|
||||
sub_uri = foo.children["sub"] = self.makedir().get_uri()
|
||||
sub = self.nodes[sub_uri]
|
||||
|
||||
blocking_uri = self.makefile(1)
|
||||
blocking_uri = self.make_smallfile(1)
|
||||
foo.children["blockingfile"] = blocking_uri
|
||||
|
||||
baz_file = self.makefile(2)
|
||||
@ -217,6 +217,18 @@ class Web(unittest.TestCase):
|
||||
self.files[newuri] = contents
|
||||
return newuri
|
||||
|
||||
def make_smallfile(self, number):
|
||||
n = str(number)
|
||||
assert len(n) == 1
|
||||
contents = "small data %s\n" % n
|
||||
newuri = uri.pack_lit(contents)
|
||||
assert newuri not in self.nodes
|
||||
assert newuri not in self.files
|
||||
node = MyFileNode(newuri, self.s)
|
||||
self.nodes[newuri] = node
|
||||
self.files[newuri] = contents
|
||||
return newuri
|
||||
|
||||
def makedir(self):
|
||||
node = MyDirectoryNode(self.nodes, self.files, self.s)
|
||||
return node
|
||||
|
@ -12,6 +12,17 @@ def get_uri_type(uri):
|
||||
return "LIT"
|
||||
return "CHK"
|
||||
|
||||
def is_filenode_uri(uri):
|
||||
return get_uri_type(uri) in ("LIT", "CHK")
|
||||
|
||||
def get_filenode_size(uri):
|
||||
assert is_filenode_uri(uri)
|
||||
t = get_uri_type(uri)
|
||||
if t == "LIT":
|
||||
return len(unpack_lit(uri))
|
||||
return unpack_uri(uri)['size']
|
||||
|
||||
|
||||
# the URI shall be an ascii representation of the file. It shall contain
|
||||
# enough information to retrieve and validate the contents. It shall be
|
||||
# expressed in a limited character set (namely [TODO]).
|
||||
|
@ -10,7 +10,7 @@ from allmydata.util import idlib, fileutil
|
||||
import simplejson
|
||||
from allmydata.uri import unpack_uri, is_dirnode_uri
|
||||
from allmydata.interfaces import IDownloadTarget, IDirectoryNode, IFileNode
|
||||
from allmydata import upload, download
|
||||
from allmydata import upload, download, uri
|
||||
from zope.interface import implements, Interface
|
||||
import urllib
|
||||
from formless import webform
|
||||
@ -107,7 +107,7 @@ class Directory(rend.Page):
|
||||
|
||||
#extract and display file size
|
||||
try:
|
||||
size = unpack_uri(target.get_uri())['size']
|
||||
size = uri.get_filenode_size(target.get_uri())
|
||||
except AssertionError:
|
||||
size = "?"
|
||||
ctx.fillSlots("size", size)
|
||||
@ -302,11 +302,10 @@ class FileJSONMetadata(rend.Page):
|
||||
|
||||
def renderNode(self, filenode):
|
||||
file_uri = filenode.get_uri()
|
||||
pieces = unpack_uri(file_uri)
|
||||
data = ("filenode",
|
||||
{'mutable': False,
|
||||
'uri': file_uri,
|
||||
'size': pieces['size'],
|
||||
'size': uri.get_filenode_size(file_uri),
|
||||
})
|
||||
return simplejson.dumps(data, indent=1)
|
||||
|
||||
@ -393,11 +392,10 @@ class DirectoryJSONMetadata(rend.Page):
|
||||
for name, childnode in children.iteritems():
|
||||
if IFileNode.providedBy(childnode):
|
||||
kiduri = childnode.get_uri()
|
||||
pieces = unpack_uri(kiduri)
|
||||
kiddata = ("filenode",
|
||||
{'mutable': False,
|
||||
'uri': kiduri,
|
||||
'size': pieces['size'],
|
||||
'size': uri.get_filenode_size(kiduri),
|
||||
})
|
||||
else:
|
||||
assert IDirectoryNode.providedBy(childnode)
|
||||
|
Loading…
Reference in New Issue
Block a user