Skip to content

Commit 1786d27

Browse files
committed
Address PR review: fix extractfile fallback and add OSError handling
- Fix tar.gz extractfile() None fallback in extension_update: nested-directory search now runs whenever manifest_data is still None, not only on KeyError - Add OSError handling around write_bytes in preset --from URL path - Add OSError handling around write_bytes in extension --from URL path
1 parent 0a02369 commit 1786d27

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/specify_cli/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,8 +2650,12 @@ def preset_add(
26502650

26512651
suffix = ".tar.gz" if archive_fmt == "tar.gz" else ".zip"
26522652
archive_path = Path(tmpdir) / f"preset{suffix}"
2653-
archive_path.write_bytes(archive_data)
2654-
manifest = manager.install_from_zip(archive_path, speckit_version, priority)
2653+
try:
2654+
archive_path.write_bytes(archive_data)
2655+
manifest = manager.install_from_zip(archive_path, speckit_version, priority)
2656+
except OSError as e:
2657+
console.print(f"[red]Error:[/red] Failed to save or install archive: {e}")
2658+
raise typer.Exit(1)
26552659

26562660
console.print(f"[green]✓[/green] Preset '{manifest.name}' v{manifest.version} installed (priority {priority})")
26572661

@@ -3672,6 +3676,9 @@ def extension_add(
36723676
except urllib.error.URLError as e:
36733677
console.print(f"[red]Error:[/red] Failed to download from {from_url}: {e}")
36743678
raise typer.Exit(1)
3679+
except OSError as e:
3680+
console.print(f"[red]Error:[/red] Failed to save or install archive: {e}")
3681+
raise typer.Exit(1)
36753682
finally:
36763683
# Clean up the downloaded archive
36773684
if archive_path is not None and archive_path.exists():
@@ -4347,7 +4354,10 @@ def extension_update(
43474354
with f:
43484355
manifest_data = yaml.safe_load(f.read()) or {}
43494356
except KeyError:
4350-
# Look for extension.yml in a single top-level subdirectory
4357+
pass
4358+
# Fall back to nested-directory search if root-level
4359+
# was missing (KeyError) or not a regular file (None).
4360+
if manifest_data is None:
43514361
members = [m for m in tf.getmembers() if m.name.endswith("/extension.yml") and m.name.count("/") == 1]
43524362
if len(members) == 1:
43534363
f = tf.extractfile(members[0])

0 commit comments

Comments
 (0)