From c5c7e5e1620ef9a25a8809548e16a25699c66bf0 Mon Sep 17 00:00:00 2001 From: gilesb Date: Mon, 12 Jan 2026 19:07:45 +0000 Subject: [PATCH] Fix file_hash called after move in cache_manager.put The dual-indexing code was calling file_hash(source_path) after cache.put(move=True) had already moved the file, causing "No such file or directory" errors on upload. Now computes local_hash before the move operation. Co-Authored-By: Claude Opus 4.5 --- cache_manager.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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]}...")