~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/download_ui.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-09-07 11:29:11 UTC
  • mfrom: (128.1.60 less-file-change-access)
  • Revision ID: pqm@pqm.ubuntu.com-20070907112911-ilw15rioduh413h0
[r=spiv] merge less-file-change-access; should improve performance and reduce resource consumption

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
        z = time.time()
48
48
        h = self._branch.get_history()
49
49
        
50
 
        if len(args) < 2:
51
 
            raise HTTPRedirect(self._branch.url('/changes'))
52
 
        
53
 
        revid = h.fix_revid(args[0])
54
 
        file_id = args[1]
55
 
        path, filename, content = h.get_file(file_id, revid)
56
 
        mime_type, encoding = mimetypes.guess_type(filename)
57
 
        if mime_type is None:
58
 
            mime_type = 'application/octet-stream'
59
 
 
60
 
        self.log.info('/download %s @ %s (%d bytes)', path, h.get_revno(revid), len(content))
61
 
        response.headers['Content-Type'] = mime_type
62
 
        response.headers['Content-Length'] = len(content)
63
 
        response.headers['Content-Disposition'] = 'attachment; filename=%s'%(filename,)
64
 
        response.body = content
65
 
        return response.body
 
50
        h._branch.lock_read()
 
51
        try:
 
52
            if len(args) < 2:
 
53
                raise HTTPRedirect(self._branch.url('/changes'))
 
54
 
 
55
            revid = h.fix_revid(args[0])
 
56
            file_id = args[1]
 
57
            path, filename, content = h.get_file(file_id, revid)
 
58
            mime_type, encoding = mimetypes.guess_type(filename)
 
59
            if mime_type is None:
 
60
                mime_type = 'application/octet-stream'
 
61
 
 
62
            self.log.info('/download %s @ %s (%d bytes)', path, h.get_revno(revid), len(content))
 
63
            response.headers['Content-Type'] = mime_type
 
64
            response.headers['Content-Length'] = len(content)
 
65
            response.headers['Content-Disposition'] = 'attachment; filename=%s'%(filename,)
 
66
            response.body = content
 
67
            return response.body
 
68
        finally:
 
69
            h._branch.unlock()