+
+def _contains_hidden_files(repo, dir_item):
+ """Return true if the directory contains items with names other than
+ '.' and '..' that begin with '.'
+
+ """
+ for name, item in vfs.contents(repo, dir_item, want_meta=False):
+ if name in ('.', '..'):
+ continue
+ if name.startswith('.'):
+ return True
+ return False
+
+
+def _dir_contents(repo, resolution, show_hidden=False):
+ """Yield the display information for the contents of dir_item."""
+
+ url_query = '?hidden=1' if show_hidden else ''
+
+ def display_info(name, item, resolved_item, display_name=None):
+ # link should be based on fully resolved type to avoid extra
+ # HTTP redirect.
+ if stat.S_ISDIR(vfs.item_mode(resolved_item)):
+ link = urllib.quote(name) + '/'
+ else:
+ link = urllib.quote(name)
+
+ size = vfs.item_size(repo, item)
+ if opt.human_readable:
+ display_size = format_filesize(size)
+ else:
+ display_size = size
+
+ if not display_name:
+ mode = vfs.item_mode(item)
+ if stat.S_ISDIR(mode):
+ display_name = name + '/'
+ elif stat.S_ISLNK(mode):
+ display_name = name + '@'
+ else:
+ display_name = name
+
+ return display_name, link + url_query, display_size
+
+ dir_item = resolution[-1][1]
+ for name, item in vfs.contents(repo, dir_item):
+ if not show_hidden:
+ if (name not in ('.', '..')) and name.startswith('.'):
+ continue
+ if name == '.':
+ yield display_info(name, item, item, '.')
+ parent_item = resolution[-2][1] if len(resolution) > 1 else dir_item
+ yield display_info('..', parent_item, parent_item, '..')
+ continue
+ res = vfs.try_resolve(repo, name, parent=resolution, want_meta=False)
+ res_name, res_item = res[-1]
+ yield display_info(name, item, res_item)
+
+
+class BupRequestHandler(tornado.web.RequestHandler):
+
+ def initialize(self, repo=None):
+ self.repo = repo
+
+ def decode_argument(self, value, name=None):
+ if name == 'path':
+ return value
+ return super(BupRequestHandler, self).decode_argument(value, name)
+
+ def get(self, path):
+ return self._process_request(path)
+
+ def head(self, path):
+ return self._process_request(path)
+
+ def _process_request(self, path):
+ path = urllib.unquote(path)
+ print('Handling request for %s' % path)
+ # Set want_meta because dir metadata won't be fetched, and if
+ # it's not a dir, then we're going to want the metadata.
+ res = vfs.resolve(self.repo, path, want_meta=True)
+ leaf_name, leaf_item = res[-1]
+ if not leaf_item: