gitstorage: crash the worker if git repository is in an inconsistent state
While encountering the issue with #66 (closed), rmtree removed the .git but failed with other files.
This led to an inconsistent state for the git repository of the package openscand.
The worker, trying to update the git repo, failed and crash:
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: 2019-07-23 +0000 11:00:06,445 DEBUG [debexpo.lib.gitstorage] directory exist, taking it as a git repository
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: Traceback (most recent call last):
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: File "/var/www/debexpo/bin/debexpo_worker.py", line 252, in <module>
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: worker.run()
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: File "/var/www/debexpo/bin/debexpo_worker.py", line 227, in run
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: self.jobs[job]['module'].invoke()
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: File "/home/expo/debexpo/debexpo/cronjobs/importuploads.py", line 113, in invoke
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: returncode = importer.main(no_env=True)
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: File "/home/expo/debexpo/debexpo/importer/importer.py", line 829, in main
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: self._store_source_as_git_repo()
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: File "/home/expo/debexpo/debexpo/importer/importer.py", line 583, in _store_source_as_git_repo
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: gs = GitStorage(git_storage_repo)
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: File "/home/expo/debexpo/debexpo/lib/gitstorage.py", line 88, in __init__
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: self.repo = Repo(path)
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: File "/usr/lib/python2.7/dist-packages/dulwich/repo.py", line 872, in __init__
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: "No git repository was found at %(path)s" % dict(path=root)
Jul 23 11:00:06 wv-debian-mentors1 python[15073]: dulwich.errors.NotGitRepository: No git repository was found at /var/cache/debexpo/uploaded/git/openscad
A try/except block can mitigate this issue.
Edited by Mattia Rizzolo