# dirnodes. The first takes a URI and produces a filenode or (new-style)
# dirnode. The other three create brand-new filenodes/dirnodes.
- def create_node_from_uri(self, u):
+ def create_node_from_uri(self, u, readcap=None):
# this returns synchronously.
+ if not u:
+ u = readcap
u = IURI(u)
u_s = u.to_string()
if u_s not in self._node_cache:
from allmydata.monitor import Monitor
from allmydata.util import hashutil, mathutil, base32, log
from allmydata.util.assertutil import _assert, precondition
-from allmydata.util.hashutil import netstring
-from allmydata.util.netstring import split_netstring
+from allmydata.util.netstring import netstring, split_netstring
from allmydata.uri import NewDirectoryURI, LiteralFileURI, from_string
from pycryptopp.cipher.aes import AES
return plaintext
def _create_node(self, rwcap, rocap):
- if rwcap:
- return self._client.create_node_from_uri(rwcap)
- return self._client.create_node_from_uri(rocap)
+ return self._client.create_node_from_uri(rwcap, rocap)
def _unpack_contents(self, data):
# the directory is serialized as a list of netstrings, one per child.
rwcap = None
if writeable:
rwcap = self._decrypt_rwcapdata(rwcapdata)
+ if not rwcap:
+ rwcap = None # rwcap is None or a non-empty string
+ if not rocap:
+ rocap = None # rocap is None or a non-empty string
child = self._create_node(rwcap, rocap)
metadata = simplejson.loads(metadata_s)
assert isinstance(metadata, dict)
or IDirectoryNode.providedBy(child)), (name,child)
assert isinstance(metadata, dict)
rwcap = child.get_uri() # might be RO if the child is not writeable
+ if rwcap is None:
+ rwcap = ""
assert isinstance(rwcap, str), rwcap
rocap = child.get_readonly_uri()
+ if rocap is None:
+ rocap = ""
assert isinstance(rocap, str), rocap
entry = "".join([netstring(name.encode("utf-8")),
netstring(rocap),
@return: a Deferred that fires with the new IDirectoryNode instance.
"""
- def create_node_from_uri(uri):
+ def create_node_from_uri(uri, rouri):
"""Create a new IFilesystemNode instance from the uri, synchronously.
- @param uri: a string or IURI-providing instance. This could be for a
- LiteralFileNode, a CHK file node, a mutable file node, or
- a directory node
+ @param uri: a string or IURI-providing instance, or None. This could
+ be for a LiteralFileNode, a CHK file node, a mutable file
+ node, or a directory node
+ @param rouri: a string or IURI-providing instance, or None. If the
+ main uri is None, I will use the rouri instead. If I
+ recognize the format of the main uri, I will ignore the
+ rouri (because it can be derived from the writecap).
+
@return: an instance that provides IFilesystemNode (or more usefully
one of its subclasses). File-specifying URIs will result in
IFileNode or IMutableFileNode -providing instances, like
d.addCallback(_got_data)
return d
- def create_node_from_uri(self, u):
+ def create_node_from_uri(self, u, readcap=None):
+ if not u:
+ u = readcap
u = IURI(u)
if (INewDirectoryURI.providedBy(u)
or IReadonlyNewDirectoryURI.providedBy(u)):
def get_history(self):
return None
- def create_node_from_uri(self, u):
+ def create_node_from_uri(self, u, readcap=None):
+ if not u:
+ u = readcap
u = IURI(u)
assert IMutableFileURI.providedBy(u), u
res = self.mutable_file_node_class(self).init_from_uri(u)
def get_storage_broker(self):
return self.storage_broker
- def create_node_from_uri(self, auri):
+ def create_node_from_uri(self, auri, readcap=None):
+ if not auri:
+ auri = readcap
precondition(isinstance(auri, str), auri)
u = uri.from_string(auri)
if (INewDirectoryURI.providedBy(u)