Skip to content

Commit

Permalink
treat failure to remove temporary directory as a warning instead of a…
Browse files Browse the repository at this point in the history
… failure
  • Loading branch information
CleanCut committed Sep 20, 2022
1 parent 29097cf commit 6bf8508
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions green/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,21 @@ def _main(argv, testing):
def main(argv=None, testing=False):
# create the temp dir only once (i.e., not while in the recursed call)
if os.environ.get("TMPDIR") is None: # pragma: nocover
with tempfile.TemporaryDirectory() as temp_dir_for_tests:
try:
os.environ["TMPDIR"] = temp_dir_for_tests
tempfile.tempdir = temp_dir_for_tests
return _main(argv, testing)
finally:
del os.environ["TMPDIR"]
tempfile.tempdir = None
try:
with tempfile.TemporaryDirectory() as temp_dir_for_tests:
try:
os.environ["TMPDIR"] = temp_dir_for_tests
tempfile.tempdir = temp_dir_for_tests
return _main(argv, testing)
finally:
del os.environ["TMPDIR"]
tempfile.tempdir = None
except OSError as os_error:
if os_error.errno == 39:
# "Directory not empty" when trying to delete the temp dir can just be a warning
print("warning: {}".format(os_error.strerror))
else:
raise (os_error)
else:
return _main(argv, testing)

Expand Down

0 comments on commit 6bf8508

Please sign in to comment.