Fixed uninstall rm parent folder race condition (#21424)
This commit is contained in:
		| @@ -7,6 +7,7 @@ | |||||||
| import shutil | import shutil | ||||||
| import glob | import glob | ||||||
| import tempfile | import tempfile | ||||||
|  | import errno | ||||||
| from contextlib import contextmanager | from contextlib import contextmanager | ||||||
| 
 | 
 | ||||||
| import ruamel.yaml as yaml | import ruamel.yaml as yaml | ||||||
| @@ -119,9 +120,17 @@ def remove_install_directory(self, spec, deprecated=False): | |||||||
|         path = os.path.dirname(path) |         path = os.path.dirname(path) | ||||||
|         while path != self.root: |         while path != self.root: | ||||||
|             if os.path.isdir(path): |             if os.path.isdir(path): | ||||||
|                 if os.listdir(path): |                 try: | ||||||
|                     return |  | ||||||
|                     os.rmdir(path) |                     os.rmdir(path) | ||||||
|  |                 except OSError as e: | ||||||
|  |                     if e.errno == errno.ENOENT: | ||||||
|  |                         # already deleted, continue with parent | ||||||
|  |                         pass | ||||||
|  |                     elif e.errno == errno.ENOTEMPTY: | ||||||
|  |                         # directory wasn't empty, done | ||||||
|  |                         return | ||||||
|  |                     else: | ||||||
|  |                         raise e | ||||||
|             path = os.path.dirname(path) |             path = os.path.dirname(path) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 BenWeber42
					BenWeber42