diff options
author | BenWeber42 <dev.ben.weber@gmail.com> | 2021-02-09 19:05:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-09 10:05:06 -0800 |
commit | e4d74825f3ec1d95eb79a01eb109a4ce863609c6 (patch) | |
tree | 84b4334804c6724deca821c3e81236729b67fdf9 | |
parent | b802e75274af6306c69a7d11ae52669009d60232 (diff) | |
download | spack-e4d74825f3ec1d95eb79a01eb109a4ce863609c6.tar.gz spack-e4d74825f3ec1d95eb79a01eb109a4ce863609c6.tar.bz2 spack-e4d74825f3ec1d95eb79a01eb109a4ce863609c6.tar.xz spack-e4d74825f3ec1d95eb79a01eb109a4ce863609c6.zip |
Fixed uninstall rm parent folder race condition (#21424)
-rw-r--r-- | lib/spack/spack/directory_layout.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/spack/spack/directory_layout.py b/lib/spack/spack/directory_layout.py index f5b2922273..145421130a 100644 --- a/lib/spack/spack/directory_layout.py +++ b/lib/spack/spack/directory_layout.py @@ -7,6 +7,7 @@ import os import shutil import glob import tempfile +import errno from contextlib import contextmanager import ruamel.yaml as yaml @@ -119,9 +120,17 @@ class DirectoryLayout(object): path = os.path.dirname(path) while path != self.root: if os.path.isdir(path): - if os.listdir(path): - return - os.rmdir(path) + 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) |