mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
bim.purge_hdf5_cache to skip currently loaded cache
Previously it would fail with: PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'bonsai\\bim\\data\\cache\\988c190483ae6bab7cf6b00cee78694d.h5'
This commit is contained in:
@@ -440,9 +440,11 @@ class SelectExpressFile(bpy.types.Operator):
|
||||
class PurgeHdf5Cache(bpy.types.Operator):
|
||||
bl_idname = "bim.purge_hdf5_cache"
|
||||
bl_label = "Purge HDF5 Cache"
|
||||
bl_description = "Clean up HDF5 cache files except the ones that currently loaded"
|
||||
|
||||
def execute(self, context):
|
||||
core.purge_hdf5_cache(tool.Debug)
|
||||
self.report({"INFO"}, "HDF5 cache purged.")
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,10 @@ class Debug(bonsai.core.tool.Debug):
|
||||
cache_dir = os.path.join(bpy.context.scene.BIMProperties.data_dir, "cache")
|
||||
filelist = [f for f in os.listdir(cache_dir) if f.endswith(".h5")]
|
||||
for f in filelist:
|
||||
os.remove(os.path.join(cache_dir, f))
|
||||
try:
|
||||
os.remove(os.path.join(cache_dir, f))
|
||||
except PermissionError:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def debug_geometry(
|
||||
|
||||
@@ -57,5 +57,10 @@ class TestPurgeHdf5Cache(NewFile):
|
||||
test_file = cache_dir / "test.h5"
|
||||
test_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
test_file.touch()
|
||||
|
||||
# Ensure it can skip currently loaded cache.
|
||||
loaded_file_path = test_file.with_stem("test_loaded")
|
||||
loaded_file = open(loaded_file_path, "w")
|
||||
|
||||
subject.purge_hdf5_cache()
|
||||
assert not [f for f in cache_dir.iterdir() if f.suffix == ".h5"]
|
||||
assert [f for f in cache_dir.iterdir() if f.suffix == ".h5"] == [loaded_file_path]
|
||||
|
||||
Reference in New Issue
Block a user