From 2af8d94cb912c7d1258916fd0a729166e137aec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 28 Feb 2018 17:02:19 +0100 Subject: [PATCH] Perform recursion after handling all blocks of current file This way file access isn't interleaved and all dependencies of one file are reported before moving to the next. --- blender_asset_tracer/tracer/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/blender_asset_tracer/tracer/__init__.py b/blender_asset_tracer/tracer/__init__.py index bade862..a89ea49 100644 --- a/blender_asset_tracer/tracer/__init__.py +++ b/blender_asset_tracer/tracer/__init__.py @@ -34,12 +34,19 @@ class _Tracer: log.info('Tracing %s', bfilepath) self.seen_files.add(bfilepath) + recurse_into = [] with blendfile.BlendFile(bfilepath) as bfile: for block in asset_holding_blocks(bfile): yield from block_walkers.from_block(block) if recursive and block.code == b'LI': - yield from self._recurse_deps(block) + recurse_into.append(block) + + # Deal with recursion after we've handled all dependencies of the + # current file, so that file access isn't interleaved and all deps + # of one file are reported before moving to the next. + for block in recurse_into: + yield from self._recurse_deps(block) def _recurse_deps(self, lib_block: blendfile.BlendFileBlock) \ -> typing.Iterator[result.BlockUsage]: