mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-06-23 09:15:32 +00:00
Use CachingDict instead of dict in dirnode.py
This commit is contained in:
@ -170,7 +170,7 @@ class NewDirectoryNode:
|
|||||||
# first we create a MutableFileNode with empty_contents, then use its
|
# first we create a MutableFileNode with empty_contents, then use its
|
||||||
# URI to create our own.
|
# URI to create our own.
|
||||||
self._node = self.filenode_class(self._client)
|
self._node = self.filenode_class(self._client)
|
||||||
empty_contents = self._pack_contents({})
|
empty_contents = self._pack_contents(CachingDict())
|
||||||
d = self._node.create(empty_contents, keypair_generator, keysize=keysize)
|
d = self._node.create(empty_contents, keypair_generator, keysize=keysize)
|
||||||
d.addCallback(self._filenode_created)
|
d.addCallback(self._filenode_created)
|
||||||
return d
|
return d
|
||||||
@ -224,9 +224,9 @@ class NewDirectoryNode:
|
|||||||
assert isinstance(data, str), (repr(data), type(data))
|
assert isinstance(data, str), (repr(data), type(data))
|
||||||
# an empty directory is serialized as an empty string
|
# an empty directory is serialized as an empty string
|
||||||
if data == "":
|
if data == "":
|
||||||
return {}
|
return CachingDict()
|
||||||
writeable = not self.is_readonly()
|
writeable = not self.is_readonly()
|
||||||
children = {}
|
children = CachingDict()
|
||||||
position = 0
|
position = 0
|
||||||
while position < len(data):
|
while position < len(data):
|
||||||
entries, position = split_netstring(data, 1, position)
|
entries, position = split_netstring(data, 1, position)
|
||||||
@ -243,27 +243,29 @@ class NewDirectoryNode:
|
|||||||
child = self._create_node(rwcap, rocap)
|
child = self._create_node(rwcap, rocap)
|
||||||
metadata = simplejson.loads(metadata_s)
|
metadata = simplejson.loads(metadata_s)
|
||||||
assert isinstance(metadata, dict)
|
assert isinstance(metadata, dict)
|
||||||
children[name] = (child, metadata)
|
children.set_both_items(name, entry, (child, metadata))
|
||||||
return children
|
return children
|
||||||
|
|
||||||
def _pack_contents(self, children):
|
def _pack_contents(self, children):
|
||||||
# expects children in the same format as _unpack_contents
|
# expects children in the same format as _unpack_contents
|
||||||
assert isinstance(children, dict)
|
assert isinstance(children, CachingDict)
|
||||||
entries = []
|
entries = []
|
||||||
for name in sorted(children.keys()):
|
for name in sorted(children.keys()):
|
||||||
child, metadata = children[name]
|
entry, metadata = children.get_both_items(name)
|
||||||
assert isinstance(name, unicode)
|
if entry == None:
|
||||||
assert IFilesystemNode.providedBy(child), (name,child)
|
child, metadata = metadata
|
||||||
assert isinstance(metadata, dict)
|
assert isinstance(name, unicode)
|
||||||
rwcap = child.get_uri() # might be RO if the child is not writeable
|
assert IFilesystemNode.providedBy(child), (name,child)
|
||||||
if rwcap is None:
|
assert isinstance(metadata, dict)
|
||||||
rwcap = ""
|
rwcap = child.get_uri() # might be RO if the child is not writeable
|
||||||
assert isinstance(rwcap, str), rwcap
|
if rwcap is None:
|
||||||
rocap = child.get_readonly_uri()
|
rwcap = ""
|
||||||
if rocap is None:
|
assert isinstance(rwcap, str), rwcap
|
||||||
rocap = ""
|
rocap = child.get_readonly_uri()
|
||||||
assert isinstance(rocap, str), rocap
|
if rocap is None:
|
||||||
entry = "".join([netstring(name.encode("utf-8")),
|
rocap = ""
|
||||||
|
assert isinstance(rocap, str), rocap
|
||||||
|
entry = "".join([netstring(name.encode("utf-8")),
|
||||||
netstring(rocap),
|
netstring(rocap),
|
||||||
netstring(self._encrypt_rwcap(rwcap)),
|
netstring(self._encrypt_rwcap(rwcap)),
|
||||||
netstring(simplejson.dumps(metadata))])
|
netstring(simplejson.dumps(metadata))])
|
||||||
|
Reference in New Issue
Block a user