Skip to content

Commit 5b8d606

Browse files
eastmadcclaude
andcommitted
fix(firmware): populate detection_roots on tar/zip-rootfs shortcut paths
The two archive-shortcut branches in FirmwareService.create_firmware (tar device-dump shortcut at line 338, zip-rootfs shortcut at line 418) previously returned firmware rows with device_metadata=NULL. Downstream walkers (hardware-firmware detection, SBOM generation, MCP file-tree tools) have to re-derive roots from extracted_path on every call, and Rule #16 explicitly names this as an anti-pattern. Fix: before each early-return, call _compute_roots_sync(fs_root) and _persist_roots(firmware, roots) to populate device_metadata['detection_roots'] inline. Both helpers are synchronous and safe inside loop.run_in_executor (already proven in firmware_paths and other callers). The result is that shortcut-path firmware now reaches the DB with detection_roots populated, matching the behaviour of the full unpack pipeline (Phase 2). Cost: one extra filesystem walk per successful shortcut, already an async executor task — no event-loop blocking. Benefit: eliminates Rule #16 violations on the two shortcut paths (previously, every ADB device dump and every rootfs ZIP left the field empty). Companion to commit 38d01d8 (find_filesystem_root fallback gate) — together they close the gap between 'tar was extracted' and 'firmware is queryable via detection_roots' for every shortcut outcome. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 38d01d8 commit 5b8d606

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

backend/app/services/firmware_service.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,18 @@ def _extract_tar():
399399
except Exception:
400400
logger.debug("Failed to parse %s", getprop_name, exc_info=True)
401401
break
402+
# Rule #16: populate detection_roots so downstream
403+
# walkers (hardware-firmware, SBOM, MCP file tree)
404+
# don't have to re-derive them from extracted_path.
405+
# Safe + synchronous — already wrapped for walk I/O.
406+
from app.services.firmware_paths import (
407+
_compute_roots_sync,
408+
_persist_roots,
409+
)
410+
roots = await loop.run_in_executor(
411+
None, _compute_roots_sync, fs_root
412+
)
413+
_persist_roots(firmware, roots)
402414
self.db.add(firmware)
403415
await self.db.flush()
404416
return firmware
@@ -479,6 +491,16 @@ def _extract_tar():
479491
firmware.kernel_path = await loop.run_in_executor(
480492
None, detect_kernel, extraction_dir, fs_root
481493
)
494+
# Rule #16: populate detection_roots so downstream walkers
495+
# don't have to re-derive them from extracted_path.
496+
from app.services.firmware_paths import (
497+
_compute_roots_sync,
498+
_persist_roots,
499+
)
500+
roots = await loop.run_in_executor(
501+
None, _compute_roots_sync, fs_root
502+
)
503+
_persist_roots(firmware, roots)
482504
self.db.add(firmware)
483505
await self.db.flush()
484506
return firmware

0 commit comments

Comments
 (0)