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
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")
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 ~")
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"))
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."
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",
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)
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
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]).
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
#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)
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)
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)