See #4657. Fallback to copying cache if moving cache fails due to permission error.

This commit is contained in:
Dion Moult
2024-05-11 19:59:39 +10:00
parent c3fbb11093
commit 00ae6809a9
+8 -1
View File
@@ -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