Skip to content

Conversation

@tabrisnet
Copy link
Collaborator

@tabrisnet tabrisnet commented Dec 13, 2025

Description

followup to #9060 and specifically #9060 (comment)

The goal is to be sure the deletion happened regardless of the explicit order of other actions within the framework, but also throw an error if the file wasn't there to be deleted.

Documentation summary for feature / change

Yes, documentation is probably needed.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Please also note any relevant details for your test configuration.

  • https://paste.armbian.com/gibadoxewo
    • --> (688) INFO: file deleted /armbian/.tmp/rootfs-6424fec5-d6f6-4f7c-9d79-540884d0449f/var/lib/dbus/machine-id [ scheduled from /armbian/lib/functions/rootfs/rootfs-create.sh create_new_rootfs_cache_via_debootstrap 345 ]
  • tar --zstd -tvf cache/rootfs/rootfs-armhf-bookworm-cli_202512-11aa195f4c01-H7f4843-B018ebe.tar.zst |grep /var/lib/dbus/machine-id
-rw-r--r-- root/root           33 2025-12-13 13:03 ./var/lib/dbus/machine-id
  • note: it's not strictly desirable that it be in the rootfs, but rather proof that it wasn't deleted until the image creation phase.

Checklist:

Please delete options that are not relevant.

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • Bug Fixes

    • File removals made more robust and verbose to improve reliability and error visibility during image creation.
  • Refactor

    • Added a deferred deletion scheduler to queue cleanup for later, improving cleanup control and robustness.
    • Adjusted startup ordering so the scheduler is available earlier during initialization.
  • Documentation

    • Minor header comment tweaks referencing internal tooling.

✏️ Tip: You can customize this high-level summary in your review settings.

@tabrisnet tabrisnet added the Work in progress Unfinished / work in progress label Dec 13, 2025
@tabrisnet tabrisnet requested a review from a team as a code owner December 13, 2025 18:34
@tabrisnet tabrisnet added the Needs Documentation New feature needs documentation entry label Dec 13, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 13, 2025

Walkthrough

Adds a deletion-scheduling facility and integrates it into library initialization; callers replace immediate rm calls with enqueueing via schedule_deletion(). A cleanup hook pre_umount_final_image__schedule_deletion_delete_now() performs queued removals during image finalization. One rm invocation was changed to use rm -fv.

Changes

Cohort / File(s) Summary
Schedule Deletion Mechanism
lib/functions/general/schedule_deletion.sh
New file. Declares declare -a schedule_deletion_files_to_delete, adds schedule_deletion(file) to enqueue paths with caller metadata (source/function/line), and adds pre_umount_final_image__schedule_deletion_delete_now() to iterate and delete queued paths with controlled errexit handling and reporting.
Library Integration
lib/library-functions.sh
Sources the new lib/functions/general/schedule_deletion.sh early in initialization (before per-file sourcing) and updates header comment references (lib/tools/gen-library.sh). Ensures scheduling functions are available at startup.
Rootfs Usage Changes
lib/functions/rootfs/rootfs-create.sh, lib/functions/rootfs/create-cache.sh
rootfs-create.sh: replaced immediate rm of ${SDCARD}/var/lib/dbus/machine-id with schedule_deletion "${SDCARD}/var/lib/dbus/machine-id". create-cache.sh: changed rm -vrm -fv for ${SDCARD}/etc/resolv.conf removal.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Review array handling and quoting in schedule_deletion.sh (edge cases, spaces, duplicates).
  • Verify caller metadata capture (BASH_SOURCE, FUNCNAME, BASH_LINENO) is correct in varied call contexts.
  • Confirm pre_umount_final_image__schedule_deletion_delete_now() lifecycle registration and that errexit/errtrace state is preserved/restored correctly.
  • Check integration order in lib/library-functions.sh to avoid initialization races.

Possibly related PRs

Suggested reviewers

  • igorpecovnik

Poem

🐰 I hop through scripts with careful cheer,
I mark old files to quietly clear.
I store their names in tidy rows,
Then nudge them gone when final goes.
🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'framework: add schedule_deletion' accurately and specifically describes the main change—introducing a new scheduling mechanism for file deletions into the framework.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added 02 Milestone: First quarter release size/small PR with less then 50 lines Needs review Seeking for review Framework Framework components labels Dec 13, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
extensions/schedule_deletion.sh (1)

16-29: Improve the success message phrasing.

The message at line 23 reads "file deleted $file" which is awkward phrasing. Consider reversing to "deleted file: $file" or "file $file deleted" for better readability.

Additionally, the logic correctly fails with exit_with_error if deletion fails (line 25), which aligns with the PR objective to "raise an error if the file to be deleted did not exist."

Example improvement:

-			display_alert "file deleted $file" "$message" "info"
+			display_alert "Deleted file" "$file: $message" "info"
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 86f473d and 214d416.

📒 Files selected for processing (3)
  • extensions/schedule_deletion.sh (1 hunks)
  • lib/functions/rootfs/create-cache.sh (1 hunks)
  • lib/functions/rootfs/rootfs-create.sh (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: tabrisnet
Repo: armbian/build PR: 0
File: :0-0
Timestamp: 2025-10-24T04:46:22.901Z
Learning: In lib/functions/rootfs/rootfs-create.sh, the FIXME comment about mmdebstrap usage with --aptopt is a future note related to PR #8785, which hasn't been merged yet.
📚 Learning: 2025-10-24T04:46:22.901Z
Learnt from: tabrisnet
Repo: armbian/build PR: 0
File: :0-0
Timestamp: 2025-10-24T04:46:22.901Z
Learning: In lib/functions/rootfs/rootfs-create.sh, the FIXME comment about mmdebstrap usage with --aptopt is a future note related to PR #8785, which hasn't been merged yet.

Applied to files:

  • lib/functions/rootfs/rootfs-create.sh
🧬 Code graph analysis (3)
extensions/schedule_deletion.sh (2)
extensions/cleanup-space-final-image.sh (2)
  • pre_umount_final_image__999_show_space_usage (33-36)
  • post_umount_final_image__200_zerofree (19-31)
lib/functions/general/extensions.sh (1)
  • cleanup_handler_extensions (378-387)
lib/functions/rootfs/rootfs-create.sh (1)
extensions/schedule_deletion.sh (1)
  • schedule_deletion (7-14)
lib/functions/rootfs/create-cache.sh (2)
lib/functions/logging/runners.sh (1)
  • run_host_command_logged (204-206)
lib/functions/rootfs/post-tweaks.sh (1)
  • post_debootstrap_tweaks (10-34)
🔇 Additional comments (4)
extensions/schedule_deletion.sh (2)

7-14: Provenance tracking is well-implemented.

The use of BASH_SOURCE[1], FUNCNAME[1], and BASH_LINENO[0] correctly captures which code scheduled the deletion, which aids debugging and satisfies the PR goal of controlling deletion order.


1-29: Both assumptions verified as correct; no actionable issues found.

The deferred deletion design is sound. Verification confirms:

  1. The extension is sourced early via lib/library-functions.sh:677, before schedule_deletion() is called at rootfs-create.sh:345.
  2. The pre_umount_final_image__schedule_deletion_delete_now() hook is explicitly invoked by call_extension_method "pre_umount_final_image" in lib/functions/image/rootfs-to-image.sh:108. The hook naming convention follows the established framework pattern and will be automatically discovered and executed by the extension manager.

The build lifecycle correctly orders extension loading → schedule_deletion() calls → hook invocation during final image unmounting.

lib/functions/rootfs/create-cache.sh (1)

125-125: Addition of -f flag is appropriate.

The change from rm -v to rm -fv allows the command to succeed silently if the file is missing, while still providing verbose output when present. This is consistent with the pattern used elsewhere in the codebase (e.g., post-tweaks.sh line 15 in relevant_code_snippets).

lib/functions/rootfs/rootfs-create.sh (1)

339-345: Consider clarifying why two different strategies are used for machine-id handling.

The code employs two separate approaches for the machine-id files:

  • Line 344: empties /etc/machine-id immediately via echo -n ">"
  • Line 345: schedules /var/lib/dbus/machine-id for deletion in the pre-umount phase

While this dual-strategy is intentional and correct—emptying /etc/machine-id during rootfs creation prevents systemd from auto-starting services on first boot, while scheduling /var/lib/dbus/machine-id for deletion handles secondary references—the comment (lines 339–343) only explains the systemd behavior, not the rationale for the different treatment.

Consider adding a note explaining why /etc/machine-id is emptied immediately while /var/lib/dbus/machine-id is scheduled for later deletion.

@tabrisnet tabrisnet force-pushed the tabrisnet_schedule_deletion branch from 214d416 to ee7cbbc Compare December 13, 2025 18:39
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
lib/functions/general/schedule_deletion.sh (1)

5-14: Make schedule_deletion() validate input and store data without fragile ; serialization.
Today it’ll break if the path (or caller metadata) contains ;, and it happily accepts an empty $1. Consider storing separate parallel arrays, or at least reject empty input.

 function schedule_deletion() {
 	local file="$1"
+	[[ -n "$file" ]] || exit_with_error "schedule_deletion: empty file path"
 	local source="${BASH_SOURCE[1]}"
 	local func="${FUNCNAME[1]}"
 	local line="${BASH_LINENO[0]}"
 
 	schedule_deletion_files_to_delete+=("$file;$source;$func;$line")
 }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 214d416 and ee7cbbc.

📒 Files selected for processing (4)
  • lib/functions/general/schedule_deletion.sh (1 hunks)
  • lib/functions/rootfs/create-cache.sh (1 hunks)
  • lib/functions/rootfs/rootfs-create.sh (1 hunks)
  • lib/library-functions.sh (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/functions/rootfs/create-cache.sh
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-10-24T04:46:22.901Z
Learnt from: tabrisnet
Repo: armbian/build PR: 0
File: :0-0
Timestamp: 2025-10-24T04:46:22.901Z
Learning: In lib/functions/rootfs/rootfs-create.sh, the FIXME comment about mmdebstrap usage with --aptopt is a future note related to PR #8785, which hasn't been merged yet.

Applied to files:

  • lib/functions/rootfs/rootfs-create.sh
📚 Learning: 2025-09-05T12:31:03.067Z
Learnt from: Ayush1325
Repo: armbian/build PR: 8382
File: packages/bsp/usb-gadget-network/setup-usbgadget-network-multi.sh:104-105
Timestamp: 2025-09-05T12:31:03.067Z
Learning: Scripts using `set -euo pipefail` provide comprehensive error handling that automatically exits on any command failure, making explicit error handling for function calls redundant.

Applied to files:

  • lib/library-functions.sh
📚 Learning: 2025-04-28T08:27:26.890Z
Learnt from: leggewie
Repo: armbian/build PR: 8133
File: extensions/apa.sh:1-2
Timestamp: 2025-04-28T08:27:26.890Z
Learning: In the Armbian build system, extension scripts in the `extensions/` directory contain hook functions and are meant to be sourced, not executed directly. These scripts don't require a shebang or `set -euo pipefail`.

Applied to files:

  • lib/library-functions.sh
🧬 Code graph analysis (2)
lib/functions/rootfs/rootfs-create.sh (1)
lib/functions/general/schedule_deletion.sh (1)
  • schedule_deletion (7-14)
lib/functions/general/schedule_deletion.sh (5)
extensions/cleanup-space-final-image.sh (3)
  • add_host_dependencies__cleanup_space_final_image_zerofree (1-3)
  • pre_umount_final_image__999_show_space_usage (33-36)
  • post_umount_final_image__200_zerofree (19-31)
extensions/fs-cryptroot-support.sh (1)
  • post_umount_final_image__750_cryptroot_cleanup (95-97)
lib/functions/rootfs/trap-rootfs.sh (1)
  • trap_handler_cleanup_rootfs_and_image (53-82)
extensions/lowmem.sh (1)
  • pre_umount_final_image__memory_optimize_defaults (65-74)
extensions/lvm.sh (1)
  • post_umount_final_image__cleanup_lvm (77-79)
🔇 Additional comments (2)
lib/functions/rootfs/rootfs-create.sh (1)

339-346: Good switch to deferred deletion; verify the deletion hook always runs for this flow.
The callsite looks correct and keeps path semantics unchanged. Main thing to double-check is that pre_umount_final_image__schedule_deletion_delete_now() is consistently invoked in the rootfs/image pipeline(s) where create_new_rootfs_cache_via_debootstrap() is used, otherwise this becomes a no-op.

lib/library-functions.sh (1)

1-3: Sourcing schedule_deletion.sh here is the right place (init-order safe).
This ensures schedule_deletion() is available for later sourced modules without adding ad-hoc sourcing at callsites.

Also applies to: 751-759, 1188-1188

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
lib/functions/general/schedule_deletion.sh (1)

16-31: Don’t clobber the caller’s errexit (set -e) state.
set +e / unconditional set -e inside the loop can turn -e on even if it was previously off, changing behavior of any code that runs afterward.

 function pre_umount_final_image__schedule_deletion_delete_now() {
 	local file source func line message deletion_info
+	local had_errexit="no"
+	case $- in *e*) had_errexit="yes";; esac
 	for deletion_info in "${schedule_deletion_files_to_delete[@]}"; do
 		IFS=';' read -r file source func line <<< "$deletion_info"
 		message="scheduled from $source $func $line"
 
 		set +e # don't bail out, let us bail out ourselves more verbosely
 		if [[ ! -e "$file" ]]; then
 			exit_with_error "FILE DELETION FAILED (missing): '${file}'; ${message}"
 		elif rm -- "$file"; then
 			display_alert "deleted file '${file}'" "$message" "info"
 		else
 			exit_with_error "FILE DELETION FAILED: '${file}'; ${message}"
 		fi
-		set -e # restore the previous behaviour
+		[[ "$had_errexit" == "yes" ]] && set -e
 	done
 }
🧹 Nitpick comments (2)
lib/functions/general/schedule_deletion.sh (2)

5-14: Validate input + avoid “;”-delimited serialization (breaks on paths containing ;/newlines).
Right now, any ; in $file will corrupt parsing (and an empty $1 schedules a dangerous no-op / confusing error later). Consider either (a) validating $1, and (b) storing fields in separate arrays or using a NUL-delimited encoding.

 function schedule_deletion() {
 	local file="$1"
+	[[ -n "$file" ]] || exit_with_error "schedule_deletion(): missing file argument"
 	local source="${BASH_SOURCE[1]}"
 	local func="${FUNCNAME[1]}"
 	local line="${BASH_LINENO[0]}"
 
 	schedule_deletion_files_to_delete+=("$file;$source;$func;$line")
 }

16-32: Consider explicitly handling the “no scheduled deletions” case for observability.
Right now, the hook silently does nothing if the queue is empty; a debug-level alert can make it easier to confirm the hook ran during image finalization.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e61e372 and 738c7d3.

📒 Files selected for processing (1)
  • lib/functions/general/schedule_deletion.sh (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
lib/functions/general/schedule_deletion.sh (2)
extensions/lowmem.sh (1)
  • pre_umount_final_image__memory_optimize_defaults (65-74)
lib/functions/rootfs/trap-rootfs.sh (1)
  • trap_handler_cleanup_rootfs_and_image (53-82)

@tabrisnet tabrisnet force-pushed the tabrisnet_schedule_deletion branch from 738c7d3 to e79f7ef Compare December 13, 2025 19:23
@rpardini
Copy link
Member

I gotta be missing something about those two files. I can't see how making a delayed deletion helps.
If the file is missing means that whatever put them there is failing -- gotta find the "root cause" instead of ignoring errors or scheduling for later.

@github-actions github-actions bot added size/medium PR with more then 50 and less then 250 lines and removed size/small PR with less then 50 lines labels Dec 13, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
lib/functions/rootfs/rootfs-create.sh (1)

339-345: Consider the root-cause concern raised in the PR review.

The PR comments from rpardini question whether scheduling delayed deletion is the right approach: "if the file is missing it indicates the component that created the file is failing." The change moves from immediate deletion with built-in error handling (rm fails if file missing) to deferred deletion with explicit error checking in the hook.

This is a design choice: either fix why /var/lib/dbus/machine-id exists when it shouldn't, or schedule its deletion for later. The PR objectives state the goal is to "ensure file deletion occurs regardless of explicit order," which suggests ordering/sequencing is the issue, not that the file may or may not exist.

Clarify: Is the scheduling necessary because the file may be recreated by subsequent build steps, or because deletion order matters for other reasons?

If you'd like to document this design decision or consider whether fixing the root cause would be more robust, I can help with that analysis.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 738c7d3 and f8bf797.

📒 Files selected for processing (4)
  • lib/functions/general/schedule_deletion.sh (1 hunks)
  • lib/functions/rootfs/create-cache.sh (1 hunks)
  • lib/functions/rootfs/rootfs-create.sh (1 hunks)
  • lib/library-functions.sh (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/library-functions.sh
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: tabrisnet
Repo: armbian/build PR: 0
File: :0-0
Timestamp: 2025-10-24T04:46:22.901Z
Learning: In lib/functions/rootfs/rootfs-create.sh, the FIXME comment about mmdebstrap usage with --aptopt is a future note related to PR #8785, which hasn't been merged yet.
📚 Learning: 2025-10-24T04:46:22.901Z
Learnt from: tabrisnet
Repo: armbian/build PR: 0
File: :0-0
Timestamp: 2025-10-24T04:46:22.901Z
Learning: In lib/functions/rootfs/rootfs-create.sh, the FIXME comment about mmdebstrap usage with --aptopt is a future note related to PR #8785, which hasn't been merged yet.

Applied to files:

  • lib/functions/general/schedule_deletion.sh
  • lib/functions/rootfs/rootfs-create.sh
📚 Learning: 2025-09-05T12:31:03.067Z
Learnt from: Ayush1325
Repo: armbian/build PR: 8382
File: packages/bsp/usb-gadget-network/setup-usbgadget-network-multi.sh:104-105
Timestamp: 2025-09-05T12:31:03.067Z
Learning: Scripts using `set -euo pipefail` provide comprehensive error handling that automatically exits on any command failure, making explicit error handling for function calls redundant.

Applied to files:

  • lib/functions/general/schedule_deletion.sh
📚 Learning: 2025-09-25T18:37:00.330Z
Learnt from: tabrisnet
Repo: armbian/build PR: 8661
File: lib/functions/compilation/armbian-kernel.sh:194-199
Timestamp: 2025-09-25T18:37:00.330Z
Learning: In PR armbian/build#8661, line 235 of lib/functions/compilation/armbian-kernel.sh already contains the corrected comment "BPF link support for netfilter hooks" for NETFILTER_BPF_LINK, not the misleading "BPF_SYSCALL" comment that was flagged during review.

Applied to files:

  • lib/functions/general/schedule_deletion.sh
📚 Learning: 2025-07-25T03:51:50.830Z
Learnt from: EvilOlaf
Repo: armbian/build PR: 8428
File: config/boards/lckfb-taishanpi.csc:5-9
Timestamp: 2025-07-25T03:51:50.830Z
Learning: When reviewing PRs in the Armbian build system, U-Boot defconfig files and patches may be added as part of the PR changes but might not be visible in the current repository clone state during review. It's important to check the actual PR file changes directly via GitHub or the PR API to get the complete picture of what files are being added or modified.

Applied to files:

  • lib/functions/general/schedule_deletion.sh
📚 Learning: 2025-07-25T03:51:50.830Z
Learnt from: EvilOlaf
Repo: armbian/build PR: 8428
File: config/boards/lckfb-taishanpi.csc:5-9
Timestamp: 2025-07-25T03:51:50.830Z
Learning: When reviewing PRs in the Armbian build system, U-Boot defconfig files and patches may be added as part of the PR changes but might not be visible in the current repository clone state during review. It's important to check the actual PR file changes directly via GitHub API (https://api.github.com/repos/armbian/build/pulls/{pr_number}/files) to get the complete picture of what files are being added or modified, especially for U-Boot patches that will be applied during the build process.

Applied to files:

  • lib/functions/general/schedule_deletion.sh
📚 Learning: 2025-08-30T06:48:09.091Z
Learnt from: tabrisnet
Repo: armbian/build PR: 0
File: :0-0
Timestamp: 2025-08-30T06:48:09.091Z
Learning: In lib/functions/compilation/armbian-kernel.sh, the user prefers flexible grep patterns over anchored ones for BTRFS configuration checks, but agrees to use quiet grep (-q) to avoid polluting build logs.

Applied to files:

  • lib/functions/general/schedule_deletion.sh
📚 Learning: 2025-08-14T17:19:39.693Z
Learnt from: leggewie
Repo: armbian/build PR: 8502
File: config/desktop/trixie/environments/i3-wm/config_base/packages:44-44
Timestamp: 2025-08-14T17:19:39.693Z
Learning: When a PR author provides clear context about package transitions in the commit message and the changes are scoped to specific release pockets, focus the review on validating those specific changes rather than suggesting broader investigations across other releases or additional dependency verifications.

Applied to files:

  • lib/functions/general/schedule_deletion.sh
🧬 Code graph analysis (2)
lib/functions/rootfs/rootfs-create.sh (1)
lib/functions/general/schedule_deletion.sh (1)
  • schedule_deletion (7-14)
lib/functions/rootfs/create-cache.sh (1)
lib/functions/logging/runners.sh (1)
  • run_host_command_logged (204-206)
🔇 Additional comments (4)
lib/functions/rootfs/create-cache.sh (1)

125-126: Consider the implications of changing to rm -fv on a file that should exist.

Using the -f (force) flag on /etc/resolv.conf causes rm to succeed silently if the file is missing, which contradicts the PR objective to "throw an error if the file did not exist to be deleted." If this file is guaranteed to exist after extraction (line 113), the original rm -v semantics—failing on a missing file—seems more aligned with catching unexpected extraction failures.

Is this change intentional to be more lenient, or does it conflict with the stated PR goal?

lib/functions/general/schedule_deletion.sh (2)

7-14: Approve schedule_deletion() function implementation.

The schedule_deletion() function correctly captures caller context (BASH_SOURCE, FUNCNAME, BASH_LINENO) and encodes it for later processing. The use of a semicolon-delimited format and appending to the global array is straightforward and maintainable.


16-43: The deletion hook is properly wired and invoked—this concern is unfounded.

The pre_umount_final_image__schedule_deletion_delete_now() function is registered and called correctly. At lib/functions/image/rootfs-to-image.sh:108, call_extension_method "pre_umount_final_image" explicitly invokes all pre_umount_final_image__* functions, including your deletion handler, before unmounting the rootfs. This occurs after schedule_deletion() calls are made from rootfs-create.sh:345, ensuring correct ordering.

If files remain in the rootfs image, the issue lies elsewhere—either files aren't being scheduled for deletion in the first place, or there's a logic problem in the deletion function itself. The hook infrastructure is sound.

lib/functions/rootfs/rootfs-create.sh (1)

344-345: Confirm the scheduling mechanism is initialized before this call.

Line 345 calls schedule_deletion(), which depends on the global array schedule_deletion_files_to_delete being declared and the scheduling framework being loaded. Please verify:

  1. Is lib/functions/general/schedule_deletion.sh sourced before rootfs-create.sh is executed?
  2. Is the sourcing order documented in lib/library-functions.sh (mentioned in the AI summary)?

@tabrisnet
Copy link
Collaborator Author

I gotta be missing something about those two files. I can't see how making a delayed deletion helps. If the file is missing means that whatever put them there is failing -- gotta find the "root cause" instead of ignoring errors or scheduling for later.

the proximate cause of /var/lib/dbus/machine-id being missing would be [and has been with testing around APA with questing] not having installed the package that creates it.
scheduling it for later means we might pull in the dbus package somewhere/sometime else [say when we install some package that depends on it].
resolv.conf? I dunno, that wasn't strictly my idea. And the case of rm -fv /etc/resolv.conf appears to be reasonable at both call-sites as the program immediately recreates it with specific content.
HOWEVER: I did run into issues with it being a symlink without resolved running or creating the appropriate file under /run/. but that was a runtime issue, not during build.

@tabrisnet
Copy link
Collaborator Author

tabrisnet commented Dec 13, 2025

Actionable comments posted: 0
🧹 Nitpick comments (1)

lib/functions/rootfs/rootfs-create.sh (1)> 339-345: Consider the root-cause concern raised in the PR review.

The PR comments from rpardini question whether scheduling delayed deletion is the right approach: "if the file is missing it indicates the component that created the file is failing." The change moves from immediate deletion with built-in error handling (rm fails if file missing) to deferred deletion with explicit error checking in the hook.
This is a design choice: either fix why /var/lib/dbus/machine-id exists when it shouldn't, or schedule its deletion for later. The PR objectives state the goal is to "ensure file deletion occurs regardless of explicit order," which suggests ordering/sequencing is the issue, not that the file may or may not exist.
Clarify: Is the scheduling necessary because the file may be recreated by subsequent build steps, or because deletion order matters for other reasons?
If you'd like to document this design decision or consider whether fixing the root cause would be more robust, I can help with that analysis.

📜 Review details

@coderabbitai
The reason it will exist is a package install. The reason it might not exist is we didn't install the package [yet].
We don't want it to exist on first-boot. that it gets created is due to an upstream package.
But it is important that the package get installed, but there is other work in-progress to affect the order/timing of package installation.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 13, 2025

Tip

For best results, initiate chat on the files or code changes.

@tabrisnet, thank you for the clarification! That makes perfect sense now.

The design rationale is sound:

  • The /var/lib/dbus/machine-id file is legitimately created by the dbus package during installation
  • Package installation timing is variable (and being refined in other work)
  • The file must be removed from the final image so it's generated fresh on first boot
  • Scheduling the deletion ensures it happens after all package operations complete, regardless of when dbus gets installed

This handles the variable timing elegantly—rather than trying to enforce strict ordering of package installations (which you noted is evolving), the scheduled deletion acts as a cleanup pass that runs at a well-defined point before image finalization. If the package hasn't been installed, the scheduled deletion will catch the missing file with an appropriate error message.

This pattern is particularly useful for build systems where component ordering may vary but certain cleanup operations must always occur.


✏️ Learnings added
Learnt from: tabrisnet
URL: https://github.com/armbian/build/pull/9064

Timestamp: 2025-12-13T23:43:54.689Z
Learning: In the Armbian build framework, the schedule_deletion mechanism is used to handle files that are created by package installations at variable times but must be removed before image finalization. For example, /var/lib/dbus/machine-id is created by the dbus package but should not exist in the final image (it should be generated on first boot). Scheduling the deletion ensures removal happens after all package operations complete, regardless of installation timing.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: tabrisnet
Repo: armbian/build PR: 0
File: :0-0
Timestamp: 2025-10-24T04:46:22.901Z
Learning: In lib/functions/rootfs/rootfs-create.sh, the FIXME comment about mmdebstrap usage with --aptopt is a future note related to PR #8785, which hasn't been merged yet.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 13, 2025

Tip

For best results, initiate chat on the files or code changes.

@tabrisnet, thank you for the clarification! That makes perfect sense now.

The scheduling approach is the right solution for this scenario:

  • The dbus package creates /var/lib/dbus/machine-id when installed
  • Package installation timing can vary during the build process (and is being actively refactored)
  • Scheduling the deletion ensures it's removed at the end regardless of when the package gets installed
  • This guarantees the file won't exist on first-boot, allowing the system to generate a fresh machine-id

This is a clean way to handle the non-deterministic ordering of package installations without having to track or control every point where the dbus package might be pulled in as a dependency.


✏️ Learnings added
Learnt from: tabrisnet
URL: https://github.com/armbian/build/pull/9064

Timestamp: 2025-12-13T23:44:04.989Z
Learning: In lib/functions/rootfs/rootfs-create.sh, the schedule_deletion for /var/lib/dbus/machine-id is necessary because: (1) the file is created by the dbus package during installation, (2) package installation timing varies during the build process and is being actively worked on, (3) scheduling the deletion ensures it's removed at the end regardless of when the package gets installed, (4) the file must not exist on first-boot so the system generates a fresh machine-id.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: tabrisnet
Repo: armbian/build PR: 0
File: :0-0
Timestamp: 2025-10-24T04:46:22.901Z
Learning: In lib/functions/rootfs/rootfs-create.sh, the FIXME comment about mmdebstrap usage with --aptopt is a future note related to PR #8785, which hasn't been merged yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

02 Milestone: First quarter release Framework Framework components Needs Documentation New feature needs documentation entry Needs review Seeking for review size/medium PR with more then 50 and less then 250 lines Work in progress Unfinished / work in progress

Development

Successfully merging this pull request may close these issues.

2 participants