Mercurial > hg
annotate hgext/lfs/wireprotolfsserver.py @ 37562:e5cd8d1a094d
lfs: special case the null:// usercache instead of treating it as a url
The previous code worked on Windows, but not on Unix, and a pending patch's test
failed. The url being used was something like "/tmp/.../client1/null://",
courtesy of ui.configpath(). Looking at the doc comment, this seems like it's
maybe not the right function to call (why should a relative cache path be
expanded relative to the repo root or config file?), but largefiles has been
using it since 8b8dd13295db (Oct 2011). It was introduced in 1b591f9b7fd2 (Jan
2011) without comment or callers. A grep over the whole history shows that only
largefiles used it until lfs and infinitepush came along recently.
It looks like if the `if not os.path.isabs(v) or "://" not in v` in configpath()
is changed to an 'and', both Linux and Windows are happy. I'm guessing that
"://" is to pick off URLs, so that seems reasonable. But I'm not sure why it
isn't explicitly "file://", and I thought that "file://foo" is relative anyway.
(At least, there are doctests for file:///tmp in util.url.) There is no mention
of this setting in the help, but it is referenced on the wiki page for
largefiles. (There's no mention that this is intended to be a URL, and the
example uses an absolute path.)
I don't want this blocking the rest of the lfs server discovery stuff. It was
also wrong to allow a file:// URL here, but not in largefiles.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 11 Apr 2018 17:29:55 -0400 |
parents | 9640ccf44ac0 |
children | b03f2e0fdb88 |
rev | line source |
---|---|
37147
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
1 # wireprotolfsserver.py - lfs protocol server side implementation |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
2 # |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
3 # Copyright 2018 Matt Harbison <matt_harbison@yahoo.com> |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
4 # |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
7 |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
8 from __future__ import absolute_import |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
9 |
37148
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
10 import datetime |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
11 import errno |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
12 import json |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
13 |
37147
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
14 from mercurial.hgweb import ( |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
15 common as hgwebcommon, |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
16 ) |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
17 |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
18 from mercurial import ( |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
19 pycompat, |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
20 ) |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
21 |
37148
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
22 HTTP_OK = hgwebcommon.HTTP_OK |
37149
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
23 HTTP_CREATED = hgwebcommon.HTTP_CREATED |
37148
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
24 HTTP_BAD_REQUEST = hgwebcommon.HTTP_BAD_REQUEST |
37250
9640ccf44ac0
lfs: ensure the transfer request is for a known URI
Matt Harbison <matt_harbison@yahoo.com>
parents:
37249
diff
changeset
|
25 HTTP_NOT_FOUND = hgwebcommon.HTTP_NOT_FOUND |
37148
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
26 |
37147
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
27 def handlewsgirequest(orig, rctx, req, res, checkperm): |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
28 """Wrap wireprotoserver.handlewsgirequest() to possibly process an LFS |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
29 request if it is left unprocessed by the wrapped method. |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
30 """ |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
31 if orig(rctx, req, res, checkperm): |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
32 return True |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
33 |
37248
dfb38c4850a9
lfs: add an experimental knob to disable blob serving
Matt Harbison <matt_harbison@yahoo.com>
parents:
37149
diff
changeset
|
34 if not rctx.repo.ui.configbool('experimental', 'lfs.serve'): |
dfb38c4850a9
lfs: add an experimental knob to disable blob serving
Matt Harbison <matt_harbison@yahoo.com>
parents:
37149
diff
changeset
|
35 return False |
dfb38c4850a9
lfs: add an experimental knob to disable blob serving
Matt Harbison <matt_harbison@yahoo.com>
parents:
37149
diff
changeset
|
36 |
37147
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
37 if not req.dispatchpath: |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
38 return False |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
39 |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
40 try: |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
41 if req.dispatchpath == b'.git/info/lfs/objects/batch': |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
42 checkperm(rctx, req, 'pull') |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
43 return _processbatchrequest(rctx.repo, req, res) |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
44 # TODO: reserve and use a path in the proposed http wireprotocol /api/ |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
45 # namespace? |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
46 elif req.dispatchpath.startswith(b'.hg/lfs/objects'): |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
47 return _processbasictransfer(rctx.repo, req, res, |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
48 lambda perm: |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
49 checkperm(rctx, req, perm)) |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
50 return False |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
51 except hgwebcommon.ErrorResponse as e: |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
52 # XXX: copied from the handler surrounding wireprotoserver._callhttp() |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
53 # in the wrapped function. Should this be moved back to hgweb to |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
54 # be a common handler? |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
55 for k, v in e.headers: |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
56 res.headers[k] = v |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
57 res.status = hgwebcommon.statusmessage(e.code, pycompat.bytestr(e)) |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
58 res.setbodybytes(b'0\n%s\n' % pycompat.bytestr(e)) |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
59 return True |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
60 |
37148
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
61 def _sethttperror(res, code, message=None): |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
62 res.status = hgwebcommon.statusmessage(code, message=message) |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
63 res.headers[b'Content-Type'] = b'text/plain; charset=utf-8' |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
64 res.setbodybytes(b'') |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
65 |
37147
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
66 def _processbatchrequest(repo, req, res): |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
67 """Handle a request for the Batch API, which is the gateway to granting file |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
68 access. |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
69 |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
70 https://github.com/git-lfs/git-lfs/blob/master/docs/api/batch.md |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
71 """ |
37148
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
72 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
73 # Mercurial client request: |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
74 # |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
75 # HOST: localhost:$HGPORT |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
76 # ACCEPT: application/vnd.git-lfs+json |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
77 # ACCEPT-ENCODING: identity |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
78 # USER-AGENT: git-lfs/2.3.4 (Mercurial 4.5.2+1114-f48b9754f04c+20180316) |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
79 # Content-Length: 125 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
80 # Content-Type: application/vnd.git-lfs+json |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
81 # |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
82 # { |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
83 # "objects": [ |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
84 # { |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
85 # "oid": "31cf...8e5b" |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
86 # "size": 12 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
87 # } |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
88 # ] |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
89 # "operation": "upload" |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
90 # } |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
91 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
92 if (req.method != b'POST' |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
93 or req.headers[b'Content-Type'] != b'application/vnd.git-lfs+json' |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
94 or req.headers[b'Accept'] != b'application/vnd.git-lfs+json'): |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
95 # TODO: figure out what the proper handling for a bad request to the |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
96 # Batch API is. |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
97 _sethttperror(res, HTTP_BAD_REQUEST, b'Invalid Batch API request') |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
98 return True |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
99 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
100 # XXX: specify an encoding? |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
101 lfsreq = json.loads(req.bodyfh.read()) |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
102 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
103 # If no transfer handlers are explicitly requested, 'basic' is assumed. |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
104 if 'basic' not in lfsreq.get('transfers', ['basic']): |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
105 _sethttperror(res, HTTP_BAD_REQUEST, |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
106 b'Only the basic LFS transfer handler is supported') |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
107 return True |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
108 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
109 operation = lfsreq.get('operation') |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
110 if operation not in ('upload', 'download'): |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
111 _sethttperror(res, HTTP_BAD_REQUEST, |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
112 b'Unsupported LFS transfer operation: %s' % operation) |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
113 return True |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
114 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
115 localstore = repo.svfs.lfslocalblobstore |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
116 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
117 objects = [p for p in _batchresponseobjects(req, lfsreq.get('objects', []), |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
118 operation, localstore)] |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
119 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
120 rsp = { |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
121 'transfer': 'basic', |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
122 'objects': objects, |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
123 } |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
124 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
125 res.status = hgwebcommon.statusmessage(HTTP_OK) |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
126 res.headers[b'Content-Type'] = b'application/vnd.git-lfs+json' |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
127 res.setbodybytes(pycompat.bytestr(json.dumps(rsp))) |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
128 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
129 return True |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
130 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
131 def _batchresponseobjects(req, objects, action, store): |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
132 """Yield one dictionary of attributes for the Batch API response for each |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
133 object in the list. |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
134 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
135 req: The parsedrequest for the Batch API request |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
136 objects: The list of objects in the Batch API object request list |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
137 action: 'upload' or 'download' |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
138 store: The local blob store for servicing requests""" |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
139 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
140 # Successful lfs-test-server response to solict an upload: |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
141 # { |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
142 # u'objects': [{ |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
143 # u'size': 12, |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
144 # u'oid': u'31cf...8e5b', |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
145 # u'actions': { |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
146 # u'upload': { |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
147 # u'href': u'http://localhost:$HGPORT/objects/31cf...8e5b', |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
148 # u'expires_at': u'0001-01-01T00:00:00Z', |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
149 # u'header': { |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
150 # u'Accept': u'application/vnd.git-lfs' |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
151 # } |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
152 # } |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
153 # } |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
154 # }] |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
155 # } |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
156 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
157 # TODO: Sort out the expires_at/expires_in/authenticated keys. |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
158 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
159 for obj in objects: |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
160 # Convert unicode to ASCII to create a filesystem path |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
161 oid = obj.get('oid').encode('ascii') |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
162 rsp = { |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
163 'oid': oid, |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
164 'size': obj.get('size'), # XXX: should this check the local size? |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
165 #'authenticated': True, |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
166 } |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
167 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
168 exists = True |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
169 verifies = False |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
170 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
171 # Verify an existing file on the upload request, so that the client is |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
172 # solicited to re-upload if it corrupt locally. Download requests are |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
173 # also verified, so the error can be flagged in the Batch API response. |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
174 # (Maybe we can use this to short circuit the download for `hg verify`, |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
175 # IFF the client can assert that the remote end is an hg server.) |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
176 # Otherwise, it's potentially overkill on download, since it is also |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
177 # verified as the file is streamed to the caller. |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
178 try: |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
179 verifies = store.verify(oid) |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
180 except IOError as inst: |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
181 if inst.errno != errno.ENOENT: |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
182 rsp['error'] = { |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
183 'code': 500, |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
184 'message': inst.strerror or 'Internal Server Server' |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
185 } |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
186 yield rsp |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
187 continue |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
188 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
189 exists = False |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
190 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
191 # Items are always listed for downloads. They are dropped for uploads |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
192 # IFF they already exist locally. |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
193 if action == 'download': |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
194 if not exists: |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
195 rsp['error'] = { |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
196 'code': 404, |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
197 'message': "The object does not exist" |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
198 } |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
199 yield rsp |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
200 continue |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
201 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
202 elif not verifies: |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
203 rsp['error'] = { |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
204 'code': 422, # XXX: is this the right code? |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
205 'message': "The object is corrupt" |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
206 } |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
207 yield rsp |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
208 continue |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
209 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
210 elif verifies: |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
211 yield rsp # Skip 'actions': already uploaded |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
212 continue |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
213 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
214 expiresat = datetime.datetime.now() + datetime.timedelta(minutes=10) |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
215 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
216 rsp['actions'] = { |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
217 '%s' % action: { |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
218 # TODO: Account for the --prefix, if any. |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
219 'href': '%s/.hg/lfs/objects/%s' % (req.baseurl, oid), |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
220 # datetime.isoformat() doesn't include the 'Z' suffix |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
221 "expires_at": expiresat.strftime('%Y-%m-%dT%H:%M:%SZ'), |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
222 'header': { |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
223 # The spec doesn't mention the Accept header here, but avoid |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
224 # a gratuitous deviation from lfs-test-server in the test |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
225 # output. |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
226 'Accept': 'application/vnd.git-lfs' |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
227 } |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
228 } |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
229 } |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
230 |
ea6fc58524d7
lfs: add server side support for the Batch API
Matt Harbison <matt_harbison@yahoo.com>
parents:
37147
diff
changeset
|
231 yield rsp |
37147
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
232 |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
233 def _processbasictransfer(repo, req, res, checkperm): |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
234 """Handle a single file upload (PUT) or download (GET) action for the Basic |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
235 Transfer Adapter. |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
236 |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
237 After determining if the request is for an upload or download, the access |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
238 must be checked by calling ``checkperm()`` with either 'pull' or 'upload' |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
239 before accessing the files. |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
240 |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
241 https://github.com/git-lfs/git-lfs/blob/master/docs/api/basic-transfers.md |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
242 """ |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
243 |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
244 method = req.method |
37249
fe061e47a2cf
lfs: avoid an improper usage of os.path.basename() to parse a URI
Matt Harbison <matt_harbison@yahoo.com>
parents:
37248
diff
changeset
|
245 oid = req.dispatchparts[-1] |
37149
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
246 localstore = repo.svfs.lfslocalblobstore |
37147
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
247 |
37250
9640ccf44ac0
lfs: ensure the transfer request is for a known URI
Matt Harbison <matt_harbison@yahoo.com>
parents:
37249
diff
changeset
|
248 if len(req.dispatchparts) != 4: |
9640ccf44ac0
lfs: ensure the transfer request is for a known URI
Matt Harbison <matt_harbison@yahoo.com>
parents:
37249
diff
changeset
|
249 _sethttperror(res, HTTP_NOT_FOUND) |
9640ccf44ac0
lfs: ensure the transfer request is for a known URI
Matt Harbison <matt_harbison@yahoo.com>
parents:
37249
diff
changeset
|
250 return True |
9640ccf44ac0
lfs: ensure the transfer request is for a known URI
Matt Harbison <matt_harbison@yahoo.com>
parents:
37249
diff
changeset
|
251 |
37147
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
252 if method == b'PUT': |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
253 checkperm('upload') |
37149
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
254 |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
255 # TODO: verify Content-Type? |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
256 |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
257 existed = localstore.has(oid) |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
258 |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
259 # TODO: how to handle timeouts? The body proxy handles limiting to |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
260 # Content-Length, but what happens if a client sends less than it |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
261 # says it will? |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
262 |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
263 # TODO: download() will abort if the checksum fails. It should raise |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
264 # something checksum specific that can be caught here, and turned |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
265 # into an http code. |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
266 localstore.download(oid, req.bodyfh) |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
267 |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
268 statusmessage = hgwebcommon.statusmessage |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
269 res.status = statusmessage(HTTP_OK if existed else HTTP_CREATED) |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
270 |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
271 # There's no payload here, but this is the header that lfs-test-server |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
272 # sends back. This eliminates some gratuitous test output conditionals. |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
273 res.headers[b'Content-Type'] = b'text/plain; charset=utf-8' |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
274 res.setbodybytes(b'') |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
275 |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
276 return True |
37147
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
277 elif method == b'GET': |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
278 checkperm('pull') |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
279 |
37149
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
280 res.status = hgwebcommon.statusmessage(HTTP_OK) |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
281 res.headers[b'Content-Type'] = b'application/octet-stream' |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
282 |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
283 # TODO: figure out how to send back the file in chunks, instead of |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
284 # reading the whole thing. |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
285 res.setbodybytes(localstore.read(oid)) |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
286 |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
287 return True |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
288 else: |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
289 _sethttperror(res, HTTP_BAD_REQUEST, |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
290 message=b'Unsupported LFS transfer method: %s' % method) |
cc0a6ea95d98
lfs: add support for serving blob files
Matt Harbison <matt_harbison@yahoo.com>
parents:
37148
diff
changeset
|
291 return True |