From 8e6d122ecf242e44132e00f8d89860b60dff0570 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 6 Oct 2008 21:35:39 -0700 Subject: [PATCH] web: rewrite t=deep-size in terms of deep-stats, update test to match inclusion of directory sizes --- docs/webapi.txt | 10 +++++----- src/allmydata/test/test_web.py | 8 +++++--- src/allmydata/web/directory.py | 12 +++++------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/webapi.txt b/docs/webapi.txt index 97f3baf5..a02b3af8 100644 --- a/docs/webapi.txt +++ b/docs/webapi.txt @@ -876,11 +876,11 @@ GET $DIRURL?t=manifest GET $DIRURL?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. + directories and 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 mutable files, nor does it take expansion or + encoding overhead into account. Later versions of the code may improve this + estimate upwards. GET $DIRURL?t=deep-stats diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 93d7ce38..05957712 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -839,9 +839,11 @@ class Web(WebMixin, unittest.TestCase): 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) + def _got(res): + self.failUnless(re.search(r'^\d+$', res), res) + size = int(res) + # with directories, the size varies. I've seen 1967 to 1979 + self.failUnless(abs(size-1973) < 10, size) d.addCallback(_got) return d diff --git a/src/allmydata/web/directory.py b/src/allmydata/web/directory.py index f6b8055e..359f0521 100644 --- a/src/allmydata/web/directory.py +++ b/src/allmydata/web/directory.py @@ -690,13 +690,11 @@ class Manifest(rend.Page): return ctx.tag def DeepSize(ctx, dirnode): - d = 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 + d = dirnode.deep_stats() + def _measure_size(stats): + total = (stats.get("size-immutable-files", 0) + + stats.get("size-mutable-files", 0) + + stats.get("size-directories", 0)) return str(total) d.addCallback(_measure_size) d.addCallback(text_plain, ctx) -- 2.45.2