Fixed uninstall rm parent folder race condition (#21424)
This commit is contained in:
parent
b802e75274
commit
e4d74825f3
@ -7,6 +7,7 @@
|
||||
import shutil
|
||||
import glob
|
||||
import tempfile
|
||||
import errno
|
||||
from contextlib import contextmanager
|
||||
|
||||
import ruamel.yaml as yaml
|
||||
@ -119,9 +120,17 @@ def remove_install_directory(self, spec, deprecated=False):
|
||||
path = os.path.dirname(path)
|
||||
while path != self.root:
|
||||
if os.path.isdir(path):
|
||||
if os.listdir(path):
|
||||
return
|
||||
try:
|
||||
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)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user