Handle directory conflicts with html output.

When calling html_report() if the output path already exists
instead of rewriting the files in the directory html_report
throws OSError: [Errno 17] File exists which leads to a 500
return to the api call. This commit avoids this issue by
checking if the directory exists beforehand and returning a
400 with an error message instead.

Change-Id: I061534c9ce9977692a7fc98187c4797b2ed60ab2
This commit is contained in:
Matthew Treinish
2013-01-04 11:28:26 -05:00
parent 80325d6897
commit 89f91daa49

View File

@@ -203,6 +203,9 @@ class CoverageController(object):
if xml:
self.coverInst.xml_report(outfile=path)
elif html:
if os.path.isdir(path):
msg = _("Directory conflict: %s already exists")
raise exc.HTTPBadRequest(explanation=msg)
self.coverInst.html_report(directory=path)
else:
output = open(path, 'w')