Tristan Van Berkom pushed to branch master at BuildStream / buildstream
Commits:
-
fe4fc0b5
by Tristan Van Berkom at 2018-12-26T23:19:07Z
-
c61e1793
by Tristan Van Berkom at 2018-12-26T23:19:07Z
-
50c1bb7f
by Tristan Van Berkom at 2018-12-26T23:19:07Z
-
32a101f6
by Tristan Van Berkom at 2018-12-26T23:53:29Z
3 changed files:
- buildstream/plugins/sources/_downloadablefilesource.py
- tests/sources/tar.py
- tests/testutils/runcli.py
Changes:
... | ... | @@ -231,7 +231,13 @@ class DownloadableFileSource(Source): |
231 | 231 |
if not DownloadableFileSource.__urlopener:
|
232 | 232 |
try:
|
233 | 233 |
netrc_config = netrc.netrc()
|
234 |
- except FileNotFoundError:
|
|
234 |
+ except OSError:
|
|
235 |
+ # If the .netrc file was not found, FileNotFoundError will be
|
|
236 |
+ # raised, but OSError will be raised directly by the netrc package
|
|
237 |
+ # in the case that $HOME is not set.
|
|
238 |
+ #
|
|
239 |
+ # This will catch both cases.
|
|
240 |
+ #
|
|
235 | 241 |
DownloadableFileSource.__urlopener = urllib.request.build_opener()
|
236 | 242 |
except netrc.NetrcParseError as e:
|
237 | 243 |
self.warn('{}: While reading .netrc: {}'.format(self, e))
|
... | ... | @@ -388,3 +388,19 @@ def test_netrc_already_specified_user(cli, datafiles, server_type, tmpdir): |
388 | 388 |
result = cli.run(project=project, args=['source', 'track', 'target.bst'])
|
389 | 389 |
result.assert_main_error(ErrorDomain.STREAM, None)
|
390 | 390 |
result.assert_task_error(ErrorDomain.SOURCE, None)
|
391 |
+ |
|
392 |
+ |
|
393 |
+# Test that BuildStream doesnt crash if HOME is unset while
|
|
394 |
+# the netrc module is trying to find it's ~/.netrc file.
|
|
395 |
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'fetch'))
|
|
396 |
+def test_homeless_environment(cli, tmpdir, datafiles):
|
|
397 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
398 |
+ generate_project(project, tmpdir)
|
|
399 |
+ |
|
400 |
+ # Create a local tar
|
|
401 |
+ src_tar = os.path.join(str(tmpdir), "a.tar.gz")
|
|
402 |
+ _assemble_tar(os.path.join(str(datafiles), "content"), "a", src_tar)
|
|
403 |
+ |
|
404 |
+ # Use a track, make sure the plugin tries to find a ~/.netrc
|
|
405 |
+ result = cli.run(project=project, args=['source', 'track', 'target.bst'], env={'HOME': None})
|
|
406 |
+ result.assert_success()
|
... | ... | @@ -529,13 +529,16 @@ def environment(env): |
529 | 529 |
old_env = {}
|
530 | 530 |
for key, value in env.items():
|
531 | 531 |
old_env[key] = os.environ.get(key)
|
532 |
- os.environ[key] = value
|
|
532 |
+ if value is None:
|
|
533 |
+ os.environ.pop(key, None)
|
|
534 |
+ else:
|
|
535 |
+ os.environ[key] = value
|
|
533 | 536 |
|
534 | 537 |
yield
|
535 | 538 |
|
536 | 539 |
for key, value in old_env.items():
|
537 | 540 |
if value is None:
|
538 |
- del os.environ[key]
|
|
541 |
+ os.environ.pop(key, None)
|
|
539 | 542 |
else:
|
540 | 543 |
os.environ[key] = value
|
541 | 544 |
|