CAM: Add explicit implementation of FileStore.exists(), so AssetManager.exists() does not log FileNotFound warnings
This commit is contained in:
@@ -528,10 +528,25 @@ class AssetManager:
|
||||
"""
|
||||
Returns True if the asset exists, False otherwise.
|
||||
"""
|
||||
async def _exists_async():
|
||||
asset_uri_obj = AssetUri(uri) if isinstance(uri, str) else uri
|
||||
logger.debug(
|
||||
f"ExistsAsync (internal): Looking up store '{store}'. Available stores: {list(self.stores.keys())}"
|
||||
)
|
||||
try:
|
||||
selected_store = self.stores[store]
|
||||
except KeyError:
|
||||
raise ValueError(f"No store registered for name: {store}")
|
||||
return await selected_store.exists(asset_uri_obj)
|
||||
|
||||
try:
|
||||
return self.get_raw(uri, store) is not None
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
return asyncio.run(_exists_async())
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"AssetManager.exists: Error during asyncio.run for '{uri}': {e}",
|
||||
exc_info=False,
|
||||
)
|
||||
raise
|
||||
|
||||
def fetch(
|
||||
self,
|
||||
|
||||
@@ -53,6 +53,22 @@ class AssetStore(abc.ABC):
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
async def exists(self, uri: AssetUri) -> bool:
|
||||
"""
|
||||
Check if the asset exists at the given URI.
|
||||
|
||||
Args:
|
||||
uri: The unique identifier for the asset.
|
||||
|
||||
Returns:
|
||||
True if the asset exists, False otherwise.
|
||||
"""
|
||||
try:
|
||||
await self.get(uri)
|
||||
return True
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
|
||||
@abc.abstractmethod
|
||||
async def delete(self, uri: AssetUri) -> None:
|
||||
"""
|
||||
|
||||
@@ -266,6 +266,17 @@ class FileStore(AssetStore):
|
||||
except IsADirectoryError:
|
||||
raise FileNotFoundError(f"Asset URI {uri} resolved to a directory: {path_to_read}")
|
||||
|
||||
async def exists(self, uri: AssetUri) -> bool:
|
||||
"""Check if the asset exists at the given URI."""
|
||||
try:
|
||||
await self.get(uri)
|
||||
return True
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
except IsADirectoryError:
|
||||
# If the path is a directory, it means the asset exists but is not a file.
|
||||
return False
|
||||
|
||||
async def delete(self, uri: AssetUri) -> None:
|
||||
"""Delete the asset at the given URI."""
|
||||
paths_to_delete: List[pathlib.Path] = []
|
||||
|
||||
@@ -52,6 +52,17 @@ class MemoryStore(AssetStore):
|
||||
|
||||
return self._data[asset_type][asset_id][version]
|
||||
|
||||
async def exists(self, uri: AssetUri) -> bool:
|
||||
asset_type = uri.asset_type
|
||||
asset_id = uri.asset_id
|
||||
version = uri.version or self._get_latest_version(asset_type, asset_id)
|
||||
|
||||
return (
|
||||
asset_type in self._data
|
||||
and asset_id in self._data[asset_type]
|
||||
and version in self._data[asset_type][asset_id]
|
||||
)
|
||||
|
||||
async def delete(self, uri: AssetUri) -> None:
|
||||
asset_type = uri.asset_type
|
||||
asset_id = uri.asset_id
|
||||
|
||||
Reference in New Issue
Block a user