diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-12-26 17:32:35 -0500 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-12-26 18:19:07 -0500 |
commit | fe4fc0b5b15c3c21d2503cbcefce1ae958091ad1 (patch) | |
tree | 991b322c2f4d8b383b56c1090fc0eb1935c1c55f | |
parent | 94b9948c459fba61d86c336b0eecf3c385c8625e (diff) | |
download | buildstream-fe4fc0b5b15c3c21d2503cbcefce1ae958091ad1.tar.gz |
_downloadablefilesource.py: Avoid crashes when HOME is unset
The python netrc module will raise OSError in the case
that HOME is not set, this was discovered while running
tests under tox.
-rw-r--r-- | buildstream/plugins/sources/_downloadablefilesource.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/buildstream/plugins/sources/_downloadablefilesource.py b/buildstream/plugins/sources/_downloadablefilesource.py index f5c5b3d08..b9b15e268 100644 --- a/buildstream/plugins/sources/_downloadablefilesource.py +++ b/buildstream/plugins/sources/_downloadablefilesource.py @@ -231,7 +231,13 @@ class DownloadableFileSource(Source): if not DownloadableFileSource.__urlopener: try: netrc_config = netrc.netrc() - except FileNotFoundError: + except OSError: + # If the .netrc file was not found, FileNotFoundError will be + # raised, but OSError will be raised directly by the netrc package + # in the case that $HOME is not set. + # + # This will catch both cases. + # DownloadableFileSource.__urlopener = urllib.request.build_opener() except netrc.NetrcParseError as e: self.warn('{}: While reading .netrc: {}'.format(self, e)) |