UnrecoverableFileError.
"""
+ def get_size_of_best_version():
+ """Find the size of the version that would be downloaded with
+ download_best_version(), without actually downloading the whole file.
+
+ I return a Deferred that fires with an integer.
+ """
+
def overwrite(new_contents):
"""Unconditionally replace the contents of the mutable file with new
ones. This simply chains get_servermap(MODE_WRITE) and upload(). This
raise UnrecoverableFileError("no recoverable versions")
return self._try_once_to_download_version(servermap, goal)
+ def get_size_of_best_version(self):
+ d = self.get_servermap(MODE_READ)
+ def _got_servermap(smap):
+ ver = smap.best_recoverable_version()
+ if not ver:
+ raise UnrecoverableFileError("no recoverable version")
+ return smap.size_of_version(ver)
+ d.addCallback(_got_servermap)
+ return d
+
def overwrite(self, new_contents):
return self._do_serialized(self._overwrite, new_contents)
def _overwrite(self, new_contents):
return "\x00"*16
def get_size(self):
return "?" # TODO: see mutable.MutableFileNode.get_size
+ def get_size_of_best_version(self):
+ return defer.succeed(len(self.all_contents[self.storage_index]))
def get_storage_index(self):
return self.storage_index
d.addCallback(lambda res: self.failUnlessIdentical(res, None))
d.addCallback(lambda res: n.download_best_version())
d.addCallback(lambda res: self.failUnlessEqual(res, "contents 1"))
+ d.addCallback(lambda res: n.get_size_of_best_version())
+ d.addCallback(lambda size:
+ self.failUnlessEqual(size, len("contents 1")))
d.addCallback(lambda res: n.overwrite("contents 2"))
d.addCallback(lambda res: n.download_best_version())
d.addCallback(lambda res: self.failUnlessEqual(res, "contents 2"))