151
151
req.status = req.HTTP_FORBIDDEN
152
152
req.headers_out['X-IVLE-Return-Error'] = 'Forbidden'
153
153
req.write("Forbidden")
154
elif not os.access(path, os.R_OK):
156
# If this is a repository-revision request, it needs to be treated
157
# differently than if it were a regular file request.
158
# Note: If there IS a revision requested but the file doesn't exist in
159
# that revision, this will terminate.
160
revision = _get_revision_or_die(req, svnclient, path)
162
if not os.access(path, os.R_OK):
155
163
req.status = req.HTTP_NOT_FOUND
156
164
req.headers_out['X-IVLE-Return-Error'] = 'File not found'
157
165
req.write("File not found")
160
168
req.content_type = mime_dirlisting
161
169
req.headers_out['X-IVLE-Return'] = 'Dir'
162
170
# TODO: Fix this dirty, dirty hack
163
newjson = get_dirlisting(req, svnclient, path)
171
newjson = get_dirlisting(req, svnclient, path, revision)
164
172
if ("X-IVLE-Action-Error" in req.headers_out):
165
173
newjson["Error"] = req.headers_out["X-IVLE-Action-Error"]
166
174
req.write(cjson.encode(newjson))
174
182
req.content_type = type
175
183
req.headers_out['X-IVLE-Return'] = 'File'
177
send_file(req, svnclient, path)
185
send_file(req, svnclient, path, revision)
179
187
# It's a file. Return a "fake directory listing" with just this file.
180
188
req.content_type = mime_dirlisting
181
189
req.headers_out['X-IVLE-Return'] = 'File'
182
req.write(cjson.encode(get_dirlisting(req, svnclient, path)))
190
req.write(cjson.encode(get_dirlisting(req, svnclient, path,
184
193
def _get_revision_or_die(req, svnclient, path):
185
194
"""Looks for a revision specification in req's URL.
209
def send_file(req, svnclient, path):
210
revision = _get_revision_or_die(req, svnclient, path)
218
def send_file(req, svnclient, path, revision):
219
"""Given a local absolute path to a file, sends the contents of the file
222
@param req: Request object. Will not be mutated; just reads the session.
223
@param svnclient: Svn client object.
224
@param path: String. Absolute path on the local file system. Not checked,
225
must already be guaranteed safe. May be a file or a directory.
226
@param revision: pysvn Revision object for the given path, or None.
212
229
req.write(svnclient.cat(path, revision=revision))
214
231
req.sendfile(path)
216
def get_dirlisting(req, svnclient, path):
233
def get_dirlisting(req, svnclient, path, revision):
217
234
"""Given a local absolute path, creates a directory listing object
218
235
ready to be JSONized and sent to the client.
220
req: Request object. Will not be mutated; just reads the session.
221
svnclient: Svn client object.
222
path: String. Absolute path on the local file system. Not checked,
237
@param req: Request object. Will not be mutated; just reads the session.
238
@param svnclient: Svn client object.
239
@param path: String. Absolute path on the local file system. Not checked,
223
240
must already be guaranteed safe. May be a file or a directory.
241
@param revision: pysvn Revision object for the given path, or None.
226
revision = _get_revision_or_die(req, svnclient, path)
228
244
# Start by trying to do an SVN status, so we can report file version