PY-29471 Properly delete temp directory created by means of tempdir module

Previously in case of error pip run with runpy.run_module() terminated
the execution of the script abruptly with SystemExit and this cleanup
wasn't performed.

Normally it didn't happen though, since temp directory was created on
Java side in PyPackageManagerImpl.install() that was responsible for
its removal.
This commit is contained in:
Mikhail Golubev
2018-04-20 19:34:16 +03:00
parent 7e9a2b871f
commit d280c276f9

View File

@@ -143,11 +143,12 @@ def main():
rmdir = mkdtemp_ifneeded()
pkgs = sys.argv[2:]
do_install(pkgs)
if rmdir is not None:
import shutil
shutil.rmtree(rmdir)
try:
do_install(pkgs)
finally:
if rmdir is not None:
import shutil
shutil.rmtree(rmdir)
elif cmd == 'untar':
if len(sys.argv) < 2: