mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-31 16:36:20 +00:00
mutable: add get_size_of_best_version to the interface, to simplify the web HEAD code, and tests
This commit is contained in:
parent
014c9b5969
commit
d43baa2ad7
@ -539,6 +539,13 @@ class IMutableFileNode(IFileNode, IMutableFilesystemNode):
|
||||
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
|
||||
|
@ -310,6 +310,16 @@ class MutableFileNode:
|
||||
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):
|
||||
|
@ -130,6 +130,8 @@ class FakeMutableFileNode:
|
||||
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
|
||||
|
@ -306,6 +306,9 @@ class Filenode(unittest.TestCase, testutil.ShouldFailMixin):
|
||||
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"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user