add GET /uri/URI/?t=deep-size, to compute the total size of immutable files reachable from a given directory

This commit is contained in:
Brian Warner 2008-03-27 11:33:42 -07:00
parent c04c2799bf
commit 9b3a32d0b3
4 changed files with 40 additions and 0 deletions

View File

@ -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

View File

@ -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):

View File

@ -16,6 +16,7 @@
<div>Other representations of this directory:
<a href="?t=manifest">manifest</a>,
<a href="?t=deep-size">total size</a>,
<a href="?t=uri">URI</a>,
<a href="?t=readonly-uri">read-only URI</a>,
<a href="?t=json">JSON</a>

View File

@ -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: