diff --git a/cache_manager.py b/cache_manager.py index 7505827..d754e30 100644 --- a/cache_manager.py +++ b/cache_manager.py @@ -398,6 +398,11 @@ class L1CacheManager: if existing and existing.output_path.exists(): return CachedFile.from_cache_entry(existing), cid + # Compute local hash BEFORE moving the file (for dual-indexing) + local_hash = None + if self._is_ipfs_cid(cid): + local_hash = file_hash(source_path) + # Store in local cache self.cache.put( node_id=node_id, @@ -414,11 +419,9 @@ class L1CacheManager: # Also index by local hash if cid is an IPFS CID # This ensures both IPFS CID and local hash can be used to find the file - if self._is_ipfs_cid(cid): - local_hash = file_hash(source_path) - if local_hash != cid: - self._set_content_index(local_hash, node_id) - logger.debug(f"Dual-indexed: {local_hash[:16]}... -> {node_id}") + if local_hash and local_hash != cid: + self._set_content_index(local_hash, node_id) + logger.debug(f"Dual-indexed: {local_hash[:16]}... -> {node_id}") logger.info(f"Cached: {cid[:16]}...")