From 00ae6809a92934bbfd9223f2d70f93265c1ca9ad Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 11 May 2024 19:59:39 +1000 Subject: [PATCH] See #4657. Fallback to copying cache if moving cache fails due to permission error. --- src/blenderbim/blenderbim/bim/ifc.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/blenderbim/blenderbim/bim/ifc.py b/src/blenderbim/blenderbim/bim/ifc.py index 60210e9700..3717451b65 100644 --- a/src/blenderbim/blenderbim/bim/ifc.py +++ b/src/blenderbim/blenderbim/bim/ifc.py @@ -19,6 +19,7 @@ import os import bpy import uuid +import shutil import hashlib import zipfile import tempfile @@ -121,7 +122,13 @@ class IfcStore: ifc_hash = hashlib.md5(ifc_key.encode("utf-8")).hexdigest() new_cache_path = os.path.join(bpy.context.scene.BIMProperties.data_dir, "cache", f"{ifc_hash}.h5") IfcStore.cache = None - os.replace(IfcStore.cache_path, new_cache_path) + try: + shutil.move(IfcStore.cache_path, new_cache_path) + except PermissionError: + try: + shutil.copy2(IfcStore.cache_path, new_cache_path) + except PermissionError: + pass # Well we tried. No cache for you! IfcStore.get_cache() @staticmethod