Skip to content

Conversation

Copy link

Copilot AI commented Dec 31, 2025

gen_file_contexts generates entries with only paths, missing SELinux contexts. mkfs.erofs rejects these as "invalid file type", causing odm/product/system partition builds to fail.

Changes

  • Validation layer: Added awk script to detect and repair incomplete file_contexts entries by appending partition-appropriate default contexts (vendor_file for odm/vendor, system_file for others)

  • Robust context extraction: Changed lost+found entry generation from using first line to finding first valid non-comment line with context field, with fallback to default

  • Comment/empty line handling: Explicitly skip comments and empty lines to prevent malformed entries

# Before: brittle extraction that fails on incomplete first line
lost_found_ctx=$(head -n 1 "$file_contexts" | awk '{print $2}')

# After: finds first valid entry, skips comments, has fallback
lost_found_ctx=$(awk '$0 !~ /^[[:space:]]*#/ && NF>=2 {print $2; exit}' "$file_contexts")
[[ -z "$lost_found_ctx" ]] && lost_found_ctx="$default_context"

The fix ensures all file_contexts entries conform to <path> <selinux_context> format before image creation.

Original prompt

Lgunos de estosncommits provoco 01facb6 a7bcd14 32c22518e282176e1162dd5f7d57339af9380d2e5087878d6a723ca52efce84d12770fa0ea0fa3c5 7fa2c899a39204283f715d2aada3bad48151e0ddapk
[DONE] Built SecSettings.apk
[09:22:49] [*] Building odm (erofs)... �\�[FAIL]

ERROR LOG OUTPUT:
================================================================================
| /home/runner/work/AstroROM/AstroROM/workspace/config/odm_file_contexts: line 1 has invalid file type /odm/etc
| /home/runner/work/AstroROM/AstroROM/workspace/config/odm_file_contexts: line 1 has invalid file type /odm/etc
| erofs: failed to open file contexts "/home/runner/work/AstroROM/AstroROM/workspace/config/odm_file_contexts"
| Try '/home/runner/work/AstroROM/AstroROM/utilities/erofs-utils/mkfs.erofs --help' for more information.
| mkfs.erofs 1.8.4-g620bf019
================================================================================
!!! PROCESS FAILED !!!
================================================================================
Build failed during: Building odm (erofs)
Exiting with code: 1
[09:22:50] [] Building product (erofs)... �\�[FAIL]
ERROR LOG OUTPUT:
================================================================================
| /home/runner/work/AstroROM/AstroROM/workspace/config/product_file_contexts: line 1 has invalid file type /product/app
| /home/runner/work/AstroROM/AstroROM/workspace/config/product_file_contexts: line 1 has invalid file type /product/app
| erofs: failed to open file contexts "/home/runner/work/AstroROM/AstroROM/workspace/config/product_file_contexts"
| Try '/home/runner/work/AstroROM/AstroROM/utilities/erofs-utils/mkfs.erofs --help' for more information.
| mkfs.erofs 1.8.4-g620bf019
================================================================================
!!! PROCESS FAILED !!!
================================================================================
Build failed during: Building product (erofs)
Exiting with code: 1
[09:22:50] [
] Building system (erofs)... �\�[FAIL]
ERROR LOG OUTPUT:
================================================================================
| /home/runner/work/AstroROM/AstroROM/workspace/config/system_file_contexts: line 1 has invalid file type /adb_keys
| /home/runner/work/AstroROM/AstroROM/workspace/config/system_file_contexts: line 1 has invalid file type /adb_keys
| erofs: failed to open file contexts "/home/runner/work/AstroROM/AstroROM/workspace/config/system_file_contexts"
| Try '/home/runner/work/AstroROM/AstroROM/utilities/erofs-utils/mkfs.erofs --help' for more information.
| mkfs.erofs 1.8.4-g620bf019
================================================================================
!!! PROCESS FAILED !!!
================================================================================
Build failed during: Building system (erofs)
Exiting with code: 1
Error: Process completed with exit code 1.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 6 commits December 31, 2025 10:05
Add validation and repair logic for file_contexts entries that may be missing SELinux contexts from gen_file_contexts tool. This fixes the "invalid file type" errors during erofs/ext4 image building.

- Add default SELinux contexts based on partition type (vendor_file for odm/vendor, system_file for system/product)
- Validate file_contexts entries and add missing contexts automatically
- Update lost+found entry generation with fallback to default context
- Ensures all file_contexts lines have proper format: <path> <selinux_context>

Co-authored-by: EduardoA3677 <82284031+EduardoA3677@users.noreply.github.com>
- Remove redundant case branches for product/system (use default)
- Clarify comment about empty line handling in awk script

Co-authored-by: EduardoA3677 <82284031+EduardoA3677@users.noreply.github.com>
- Simplify awk condition using else clause for better readability
- Use more robust awk-based extraction for lost_found_ctx
- Ensure extraction only succeeds when valid second field exists

Co-authored-by: EduardoA3677 <82284031+EduardoA3677@users.noreply.github.com>
- Add explicit 'next' statement to skip empty lines
- Update comments to accurately reflect behavior
- Preserve extra fields for compatibility with extended formats

Co-authored-by: EduardoA3677 <82284031+EduardoA3677@users.noreply.github.com>
- Skip comment lines starting with # in file_contexts validation
- Find first valid line with 2+ fields for context extraction (not just first line)
- Ensure lost+found context is extracted from a valid entry

Co-authored-by: EduardoA3677 <82284031+EduardoA3677@users.noreply.github.com>
- Both awk scripts now use the same pattern for detecting comments
- Improves code consistency and maintainability

Co-authored-by: EduardoA3677 <82284031+EduardoA3677@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix build error related to erofs file contexts Fix erofs build failures from incomplete file_contexts entries Dec 31, 2025
Copilot AI requested a review from EduardoA3677 December 31, 2025 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants