From: Brian Warner Date: Thu, 27 Mar 2008 18:33:42 +0000 (-0700) Subject: add GET /uri/URI/?t=deep-size, to compute the total size of immutable files reachable... X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/priv.html?a=commitdiff_plain;h=9b3a32d0b38d5d9e455bfbac6050902fa5f91b88;p=tahoe-lafs%2Ftahoe-lafs.git add GET /uri/URI/?t=deep-size, to compute the total size of immutable files reachable from a given directory --- diff --git a/docs/webapi.txt b/docs/webapi.txt index e5e492ef..b8989f72 100644 --- a/docs/webapi.txt +++ b/docs/webapi.txt @@ -561,6 +561,15 @@ GET $URL?t=manifest Return an HTML-formatted manifest of the given directory, for debugging. +GET $URL?t=deep-size + + Return a number (in bytes) containing the sum of the filesize of all + immutable files reachable from the given directory. This is a rough lower + bound of the total space consumed by this subtree. It does not include + space consumed by directories or immutable files, nor does it take + expansion or encoding overhead into account. Later versions of the code may + improve this estimate upwards. + 6. XMLRPC (coming soon) http://localhost:8123/xmlrpc diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index a55b9efb..c53b49ae 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -740,6 +740,14 @@ class Web(WebMixin, unittest.TestCase): d.addCallback(_got) return d + def test_GET_DIRURL_deepsize(self): + d = self.GET(self.public_url + "/foo?t=deep-size", followRedirect=True) + def _got(manifest): + self.failUnless(re.search(r'^\d+$', manifest), manifest) + self.failUnlessEqual("57", manifest) + d.addCallback(_got) + return d + def test_GET_DIRURL_uri(self): d = self.GET(self.public_url + "/foo?t=uri") def _check(res): diff --git a/src/allmydata/web/directory.xhtml b/src/allmydata/web/directory.xhtml index e902a217..cdd2fd91 100644 --- a/src/allmydata/web/directory.xhtml +++ b/src/allmydata/web/directory.xhtml @@ -16,6 +16,7 @@
Other representations of this directory: manifest, +total size, URI, read-only URI, JSON diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index 3b6485d1..8bda3d49 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -12,6 +12,7 @@ from allmydata.interfaces import IDownloadTarget, IDirectoryNode, IFileNode, \ IMutableFileNode import allmydata # to display import path from allmydata import download +from allmydata.uri import from_string_verifier, CHKFileVerifierURI from allmydata.upload import FileHandle, FileName from allmydata import provisioning from allmydata import get_package_versions_string @@ -1223,6 +1224,25 @@ class Manifest(rend.Page): ctx.fillSlots("refresh_capability", refresh_cap) return ctx.tag +class DeepSize(rend.Page): + + def __init__(self, dirnode, dirpath): + self._dirnode = dirnode + self._dirpath = dirpath + + def renderHTTP(self, ctx): + inevow.IRequest(ctx).setHeader("content-type", "text/plain") + d = self._dirnode.build_manifest() + def _measure_size(manifest): + total = 0 + for verifiercap in manifest: + u = from_string_verifier(verifiercap) + if isinstance(u, CHKFileVerifierURI): + total += u.size + return str(total) + d.addCallback(_measure_size) + return d + class ChildError: implements(inevow.IResource) def renderHTTP(self, ctx): @@ -1315,6 +1335,8 @@ class VDrive(rend.Page): return DirectoryReadonlyURI(node), () elif t == "manifest": return Manifest(node, path), () + elif t == "deep-size": + return DeepSize(node, path), () elif t == 'rename-form': return RenameForm(self.name, node, path), () else: