From 0f4817e3a843fcd397bde82354b966d65d3a7558 Mon Sep 17 00:00:00 2001 From: gilesb Date: Tue, 13 Jan 2026 03:45:56 +0000 Subject: [PATCH] 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 --- ipfs_client.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ipfs_client.py b/ipfs_client.py index 5079c64..85cba7c 100644 --- a/ipfs_client.py +++ b/ipfs_client.py @@ -10,7 +10,7 @@ import logging import os import re from pathlib import Path -from typing import Optional +from typing import Optional, Union 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) -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. Args: cid: IPFS CID to retrieve - dest_path: Path to save the file + dest_path: Path to save the file (Path object or string) Returns: True on success, False on failure @@ -148,6 +148,10 @@ def get_file(cid: str, dest_path: Path) -> bool: if data is None: 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.write_bytes(data) logger.info(f"Retrieved from IPFS: {cid} -> {dest_path}")