Fix http error handling

- Return "400" status when the project doesn't have a database or repo
- In case the DB is not found, properly print the corresponding
  file name in the logs

Signed-off-by: Michael Opdenacker <michael.opdenacker@bootlin.com>
This commit is contained in:
Michael Opdenacker 2019-12-18 10:13:15 +01:00
parent f4129147ad
commit 952329f32b
2 changed files with 12 additions and 4 deletions

View file

@ -22,7 +22,9 @@ import bsddb3
from io import BytesIO
import re
from lib import autoBytes
import os
import os.path
import errno
##################################################################################
@ -155,7 +157,7 @@ class DB:
if os.path.isdir(dir):
self.dir = dir
else:
raise FileNotFoundError
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), dir)
ro = readonly

View file

@ -82,6 +82,13 @@ if m:
else:
status = 400
basedir = os.environ['LXR_PROJ_DIR']
datadir = basedir + '/' + project + '/data';
repodir = basedir + '/' + project + '/repo';
if not(os.path.exists(datadir)) or not(os.path.exists(repodir)):
status = 400
if status == 301:
realprint('Status: 301 Moved Permanently')
realprint('Location: '+location+'\n')
@ -94,9 +101,8 @@ elif status == 400:
realprint('Status: 400 Bad Request\n')
exit()
basedir = os.environ['LXR_PROJ_DIR']
os.environ['LXR_DATA_DIR'] = basedir + '/' + project + '/data';
os.environ['LXR_REPO_DIR'] = basedir + '/' + project + '/repo';
os.environ['LXR_DATA_DIR'] = datadir
os.environ['LXR_REPO_DIR'] = repodir
projects = []
for (dirpath, dirnames, filenames) in os.walk(basedir):