Fix get_file to accept both Path and string arguments

All callers were passing str(path) but the function expected Path objects,
causing 'str' object has no attribute 'parent' errors when fetching from IPFS.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gilesb
2026-01-13 03:45:56 +00:00
parent 3ee4dc1efb
commit 0f4817e3a8

View File

@@ -10,7 +10,7 @@ import logging
import os import os
import re import re
from pathlib import Path from pathlib import Path
from typing import Optional from typing import Optional, Union
import requests import requests
@@ -132,13 +132,13 @@ def add_string(content: str, pin: bool = True) -> Optional[str]:
return add_bytes(content.encode('utf-8'), pin=pin) return add_bytes(content.encode('utf-8'), pin=pin)
def get_file(cid: str, dest_path: Path) -> bool: def get_file(cid: str, dest_path: Union[Path, str]) -> bool:
""" """
Retrieve a file from IPFS and save to destination. Retrieve a file from IPFS and save to destination.
Args: Args:
cid: IPFS CID to retrieve cid: IPFS CID to retrieve
dest_path: Path to save the file dest_path: Path to save the file (Path object or string)
Returns: Returns:
True on success, False on failure True on success, False on failure
@@ -148,6 +148,10 @@ def get_file(cid: str, dest_path: Path) -> bool:
if data is None: if data is None:
return False return False
# Ensure dest_path is a Path object
if isinstance(dest_path, str):
dest_path = Path(dest_path)
dest_path.parent.mkdir(parents=True, exist_ok=True) dest_path.parent.mkdir(parents=True, exist_ok=True)
dest_path.write_bytes(data) dest_path.write_bytes(data)
logger.info(f"Retrieved from IPFS: {cid} -> {dest_path}") logger.info(f"Retrieved from IPFS: {cid} -> {dest_path}")