diff --git a/lib/spack/spack/caches.py b/lib/spack/spack/caches.py index a7910905bcb5048850ff8f228da7100e43548c3b..61a47eaa6e5868bf029d4bbfcd0ec76790e311ac 100644 --- a/lib/spack/spack/caches.py +++ b/lib/spack/spack/caches.py @@ -70,7 +70,13 @@ def symlink(self, mirror_ref): relative_dst = os.path.relpath( mirror_ref.storage_path, start=os.path.dirname(cosmetic_path)) + if not os.path.exists(cosmetic_path): + if os.path.lexists(cosmetic_path): + # In this case the link itself exists but it is broken: remove + # it and recreate it (in order to fix any symlinks broken prior + # to https://github.com/spack/spack/pull/13908) + os.unlink(cosmetic_path) mkdirp(os.path.dirname(cosmetic_path)) os.symlink(relative_dst, cosmetic_path)