Skip to content

Commit 462aa42

Browse files
ctruedenclaude
andcommitted
Fix extension detection of micromamba archive
Co-authored-by: Claude <[email protected]>
1 parent fecb876 commit 462aa42

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/appose/util/download.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,39 @@ def download(
4343
"""
4444
from .filepath import file_type
4545

46+
# Resolve redirects and get final URL
47+
final_url = redirected_url(url_path)
48+
49+
# Try to get file extension from final URL (after redirects)
50+
file_ext = file_type(final_url)
51+
if not file_ext:
52+
# Try to extract filename from query parameters (e.g., ?filename=file.tar.bz2)
53+
parsed = urllib.parse.urlparse(final_url)
54+
params = urllib.parse.parse_qs(parsed.query)
55+
56+
# Check for filename in query parameters
57+
if "response-content-disposition" in params:
58+
# Parse Content-Disposition header value
59+
content_disp = params["response-content-disposition"][0]
60+
# Extract filename from 'filename="..."' or filename*=UTF-8''...
61+
import re
62+
63+
match = re.search(
64+
r'filename[*]?=(?:UTF-8\'\')?["\']?([^"\';&]+)', content_disp
65+
)
66+
if match:
67+
filename = urllib.parse.unquote(match.group(1))
68+
file_ext = file_type(filename)
69+
70+
# Fallback to original URL if still no extension
71+
if not file_ext:
72+
file_ext = file_type(url_path)
73+
4674
# Create temporary file with appropriate extension
47-
file_ext = file_type(url_path)
4875
fd, temp_path = tempfile.mkstemp(prefix=f"{name}-", suffix=file_ext)
4976
temp_file = Path(temp_path)
5077

5178
try:
52-
# Resolve redirects and get final URL
53-
final_url = redirected_url(url_path)
5479
file_size = get_file_size(final_url)
5580

5681
# Download file with progress tracking

0 commit comments

Comments
 (0)