From: Jeremy Fitzhardinge <jeremy@goop.org>
Date: Sun, 13 May 2012 03:42:52 +0000 (-0700)
Subject: Add ETags for immutable directories
X-Git-Url: https://git.rkrishnan.org/pf/vdrive/listings/?a=commitdiff_plain;h=518ef25bdb52ba1c565f1dd107883a2e2adb9e9a;p=tahoe-lafs%2Ftahoe-lafs.git

Add ETags for immutable directories

Like immutable files, the ETag is based on the storage index. However, since
a directory is a special interpretation of a file, it is distinguished from
the file by prepending "DIR:" onto the start of the ETag, and adding
-representation on the end (where -representation is the ?t= argument, json,
info, etc).

It also checks the return of setETag and avoids generating a representation
if the client already has it.
---

diff --git a/src/allmydata/web/directory.py b/src/allmydata/web/directory.py
index 55293563..80f5aa3d 100644
--- a/src/allmydata/web/directory.py
+++ b/src/allmydata/web/directory.py
@@ -153,6 +153,12 @@ class DirectoryNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin):
         req = IRequest(ctx)
         # This is where all of the directory-related ?t=* code goes.
         t = get_arg(req, "t", "").strip()
+
+        if not self.node.is_mutable():
+            si = self.node.get_storage_index()
+            if si and req.setETag('DIR:%s-%s' % (base32.b2a(si), t or "")):
+                return ""
+
         if not t:
             # render the directory as HTML, using the docFactory and Nevow's
             # whole templating thing.