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 <noreply@anthropic.com>
This commit is contained in:
@@ -398,6 +398,11 @@ class L1CacheManager:
|
|||||||
if existing and existing.output_path.exists():
|
if existing and existing.output_path.exists():
|
||||||
return CachedFile.from_cache_entry(existing), cid
|
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
|
# Store in local cache
|
||||||
self.cache.put(
|
self.cache.put(
|
||||||
node_id=node_id,
|
node_id=node_id,
|
||||||
@@ -414,11 +419,9 @@ class L1CacheManager:
|
|||||||
|
|
||||||
# Also index by local hash if cid is an IPFS CID
|
# 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
|
# This ensures both IPFS CID and local hash can be used to find the file
|
||||||
if self._is_ipfs_cid(cid):
|
if local_hash and local_hash != cid:
|
||||||
local_hash = file_hash(source_path)
|
self._set_content_index(local_hash, node_id)
|
||||||
if local_hash != cid:
|
logger.debug(f"Dual-indexed: {local_hash[:16]}... -> {node_id}")
|
||||||
self._set_content_index(local_hash, node_id)
|
|
||||||
logger.debug(f"Dual-indexed: {local_hash[:16]}... -> {node_id}")
|
|
||||||
|
|
||||||
logger.info(f"Cached: {cid[:16]}...")
|
logger.info(f"Cached: {cid[:16]}...")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user