j
This commit is contained in:
@@ -288,7 +288,7 @@ class ZeroTier(Store):
|
|||||||
url += f"{sep}api_key={self._api_key}"
|
url += f"{sep}api_key={self._api_key}"
|
||||||
return url
|
return url
|
||||||
|
|
||||||
def download_to_temp(self, file_hash: str, temp_root: Optional[Path] = None) -> Optional[Path]:
|
def download_to_temp(self, file_hash: str, temp_root: Optional[Path] = None, suffix: Optional[str] = None) -> Optional[Path]:
|
||||||
"""Download a file from the remote peer to a local temporary file."""
|
"""Download a file from the remote peer to a local temporary file."""
|
||||||
import os
|
import os
|
||||||
import httpx
|
import httpx
|
||||||
@@ -301,13 +301,19 @@ class ZeroTier(Store):
|
|||||||
if not url or not isinstance(url, str) or not url.startswith("http"):
|
if not url or not isinstance(url, str) or not url.startswith("http"):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# Ensure suffix starts with a dot if provided
|
||||||
|
if suffix and not suffix.startswith("."):
|
||||||
|
suffix = f".{suffix}"
|
||||||
|
if not suffix:
|
||||||
|
suffix = ".tmp"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Use provided temp_root or system temp
|
# Use provided temp_root or system temp
|
||||||
if temp_root:
|
if temp_root:
|
||||||
temp_root.mkdir(parents=True, exist_ok=True)
|
temp_root.mkdir(parents=True, exist_ok=True)
|
||||||
fd, tmp_path = tempfile.mkstemp(dir=str(temp_root), suffix=".tmp")
|
fd, tmp_path = tempfile.mkstemp(dir=str(temp_root), suffix=suffix)
|
||||||
else:
|
else:
|
||||||
fd, tmp_path = tempfile.mkstemp(suffix=".tmp")
|
fd, tmp_path = tempfile.mkstemp(suffix=suffix)
|
||||||
|
|
||||||
os_fd = os.fdopen(fd, 'wb')
|
os_fd = os.fdopen(fd, 'wb')
|
||||||
|
|
||||||
|
|||||||
@@ -972,8 +972,30 @@ class Add_File(Cmdlet):
|
|||||||
|
|
||||||
tmp_dir: Optional[Path] = None
|
tmp_dir: Optional[Path] = None
|
||||||
try:
|
try:
|
||||||
|
# Extract suffix from pipe_obj path to avoid .tmp rejections
|
||||||
|
suffix = None
|
||||||
|
if pipe_obj.path:
|
||||||
|
try:
|
||||||
|
suffix = Path(pipe_obj.path).suffix
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Extract suffix from metadata if available (fallback)
|
||||||
|
if not suffix:
|
||||||
|
metadata = getattr(pipe_obj, "metadata", {})
|
||||||
|
if isinstance(metadata, dict):
|
||||||
|
suffix = metadata.get("ext")
|
||||||
|
|
||||||
tmp_dir = Path(tempfile.mkdtemp(prefix="add-file-src-"))
|
tmp_dir = Path(tempfile.mkdtemp(prefix="add-file-src-"))
|
||||||
downloaded = downloader(str(file_hash), temp_root=tmp_dir)
|
|
||||||
|
# Pass suffix to downloader if it supports it
|
||||||
|
import inspect
|
||||||
|
sig = inspect.signature(downloader)
|
||||||
|
if "suffix" in sig.parameters:
|
||||||
|
downloaded = downloader(str(file_hash), temp_root=tmp_dir, suffix=suffix)
|
||||||
|
else:
|
||||||
|
downloaded = downloader(str(file_hash), temp_root=tmp_dir)
|
||||||
|
|
||||||
if isinstance(downloaded, Path) and downloaded.exists():
|
if isinstance(downloaded, Path) and downloaded.exists():
|
||||||
pipe_obj.is_temp = True
|
pipe_obj.is_temp = True
|
||||||
return downloaded, tmp_dir
|
return downloaded, tmp_dir
|
||||||
|
|||||||
Reference in New Issue
Block a user