You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(runtime): remove dropped var_files from var-staging - #445
var-staging stays between builds, and both the var image and the provision bundle are made from it. The extension and runtime var_files steps only copy files in (cp -a, cp -f). No step records what they copy or removes it later. So a file that you remove from var_files stays in var-staging and gets to the device at the next provision. This occurs when you remove a var_files entry, and also when you remove a file under an entry that is still listed.
With 1.2.0, on a project with var_files: [var/lib/app/**] and overlay/var/lib/app/a.txt:
Empty overlay directories in the extension sysroot are left as they are. That is on purpose (see the comment in ext/build.rs), and this PR does not change it.
Change
All code changes are in src/commands/runtime/build.rs.
After both copy steps, a record step writes each path that var_files placed, and each file, link and directory under it, to $AVOCADO_PREFIX/.stamps/runtime/<runtime>/var-staging.files. The list is NUL-delimited, like overlay.files.
Before anything writes to var-staging, a prune step reads the earlier list in reverse order (LC_ALL=C sort -rzu). It removes each file or link that the current var_files no longer provide. It removes a directory only when the directory is empty. It skips absolute paths and paths that contain .., with the same guard as the overlay sync.
Paths that var_files did not place are never touched. This includes docker priming in lib/docker, the lib/avocado manifest and images, and package content. The build does not wipe var-staging.
The extension var_files copy shell moves into ext_var_files_script, without a change to the copy itself. A missing source now prints a warning, as the runtime step already does.
A runtime source that ends in /. is recorded at its dest, where the shell copy puts its content.
The list is in .stamps/runtime/<runtime>/ so that avocado runtime clean removes it together with var-staging, and so that it never gets into the var image.
Upgrade note (in CHANGELOG.md): files that an older CLI copied are not on a list, so they stay until avocado runtime clean <runtime>, followed by avocado install and avocado build.
Testing
var_files_removed_between_builds_leave_var_staging runs the prune, copy and record shell with bash against a tempdir, over three builds. It covers removed files and entries, a path with a space, files that var_files did not place, and ../ and absolute paths in the list. It fails with the old copy-only behavior.
var_files_dot_source_is_recorded_where_the_copy_puts_it, var_files_copies_match_where_the_copies_put_files and build_script_prunes_var_staging_first_and_records_after_the_copies cover the path rules and the step order in the full build script.
On a real qemux86-64 project, the built binary removes lib/app/a.txt and the empty lib/app at build 2:
Removed /var/lib/app/a.txt from var staging (no longer in var_files)
Removed empty directory /var/lib/app from var staging (no longer in var_files)
cargo fmt --all -- --check and RUST_MIN_STACK=8388608 cargo test pass.
cargo clippy --all-targets --all-features -- -D warnings on macOS gives 5 dead_code errors in src/utils/host_mounts.rs. They are on main too. This change adds no warnings.
Var staging persists between builds and the var image is made from it.
The var_files copies only added files, so a file removed from an
extension's or the runtime's var_files stayed in var staging and
reached the device on the next provision.
- Move the extension var_files copy into ext_var_files_script
- Record every path the var_files copies place, NUL-delimited, in
.stamps/runtime/<runtime>/var-staging.files
- Before anything writes to var staging, remove each recorded path
that the current var_files no longer provide; remove a recorded
directory only when it is empty, and never touch unrecorded paths
or paths that leave var staging
- Test the prune, copy and record steps with bash against a tempdir
Refs: (bug)avocado-cli-S3-removed-var-files-stay-in-var-staging-and-the-var-image.md
Changes from the QA review of the var-staging prune.
- Record a runtime var_files source that ends in `/.` at its dest,
where the shell copy puts its content
- Sort the list with LC_ALL=C, as the other NUL-delimited sorts do
- Warn when an extension var_files source is not in the sysroot
- Tell users in the CHANGELOG that files from an earlier version
stay until `avocado runtime clean <runtime>`
Refs: (bug)avocado-cli-S3-removed-var-files-stay-in-var-staging-and-the-var-image.md
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The inventory can delete uncopied files outside staging through preserved symlinks, records skipped dangling links, and leaves root-destination copies untracked and unpruned.
This PR addresses stale var_files content in persistent runtime staging, which can otherwise carry removed files into later var images and provision bundles.
Changes:
Adds a per-runtime file inventory, pruning before staging writes and recording after both copy steps.
Extracts extension copy generation and adds regression tests for removal, path handling, and build-step order.
Documents the cleanup required for files copied by older CLI versions.
File
Description
src/commands/runtime/build.rs
Adds inventory and pruning helpers, integrates build steps, and tests staging cleanup.
CHANGELOG.md
Describes the fix and one-time cleanup procedure for existing projects.
…gh links
Review of the var_files record found three gaps. A runtime source that is
a symlink to a directory is copied as a link, but the record listed the
files of its target, so dropping the entry removed them through the link.
A dangling source link is not copied, but it was recorded, so dropping
the entry could remove a file at its destination that var_files never
placed. A copy into var staging itself (such as seed/conf/. to /) was not
recorded at all, so its files stayed after they left var_files.
- Record a runtime symlink source as one entry, and select sources with
the same tests the copies use, so a dangling link is never recorded
- Record and prune what a copy places in var staging itself, but never
list var staging
- Skip a listed path when a directory above it in var staging is a
symlink, so an older list cannot lead removal through a link
- Add tests for each case
Refs: #445
Remove copied special files during stale-path cleanup
src/commands/runtime/build.rs:3655
-f only matches regular files, but directory copies using cp -a also preserve FIFOs and other special files, and find records those paths. If a copied directory contains a FIFO and that file or mapping is removed, this branch never deletes it, its parent cannot be removed, and the next inventory forgets it permanently. Remove existing non-directory entries as well as symlinks, while retaining the empty-directory and symlink-ancestor safeguards.
The reason will be displayed to describe this comment to others. Learn more.
Confirmed. The prune now uses the copy step's own source test before it checks the path. A top-level source that became a dangling link no longer counts as provided, so its old copy is removed. -L still counts for links inside a copied directory. Test added. Fixed in f754b14.
A top-level var_files source that became a dangling link still counted as
provided in the prune, while the copy and the record skipped it. Its old
copy then dropped off the list and stayed in var staging for good. A FIFO
or other special file that cp -a copied inside a directory was recorded
but never removed, because the prune removed only regular files and links.
- Use the copy step's own test for the source in both the prune and the
record, so a source the copy skips provides nothing
- Remove any recorded entry that is not a directory, with the same guards
against symlinked parents and paths that leave var staging
- Add tests for a source that became a dangling link and for a FIFO that
left the source directory
Refs: #445
FIFO or other special file never removed: confirmed. The prune now removes any recorded entry that is not a directory, such as a FIFO that cp -a copied. The guards for symlinked parents and for paths that leave var staging are the same. Test added. Fixed in f754b14.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
var-staging stays between builds, and both the var image and the provision bundle are made from it. The extension and runtime
var_filessteps only copy files in (cp -a,cp -f). No step records what they copy or removes it later. So a file that you remove fromvar_filesstays in var-staging and gets to the device at the next provision. This occurs when you remove avar_filesentry, and also when you remove a file under an entry that is still listed.With 1.2.0, on a project with
var_files: [var/lib/app/**]andoverlay/var/lib/app/a.txt:Empty overlay directories in the extension sysroot are left as they are. That is on purpose (see the comment in
ext/build.rs), and this PR does not change it.Change
All code changes are in
src/commands/runtime/build.rs.var_filesplaced, and each file, link and directory under it, to$AVOCADO_PREFIX/.stamps/runtime/<runtime>/var-staging.files. The list is NUL-delimited, likeoverlay.files.LC_ALL=C sort -rzu). It removes each file or link that the currentvar_filesno longer provide. It removes a directory only when the directory is empty. It skips absolute paths and paths that contain.., with the same guard as the overlay sync.var_filesdid not place are never touched. This includes docker priming inlib/docker, thelib/avocadomanifest and images, and package content. The build does not wipe var-staging.var_filescopy shell moves intoext_var_files_script, without a change to the copy itself. A missing source now prints a warning, as the runtime step already does./.is recorded at its dest, where the shell copy puts its content.The list is in
.stamps/runtime/<runtime>/so thatavocado runtime cleanremoves it together with var-staging, and so that it never gets into the var image.Upgrade note (in
CHANGELOG.md): files that an older CLI copied are not on a list, so they stay untilavocado runtime clean <runtime>, followed byavocado installandavocado build.Testing
var_files_removed_between_builds_leave_var_stagingruns the prune, copy and record shell withbashagainst a tempdir, over three builds. It covers removed files and entries, a path with a space, files that var_files did not place, and../and absolute paths in the list. It fails with the old copy-only behavior.var_files_dot_source_is_recorded_where_the_copy_puts_it,var_files_copies_match_where_the_copies_put_filesandbuild_script_prunes_var_staging_first_and_records_after_the_copiescover the path rules and the step order in the full build script.qemux86-64project, the built binary removeslib/app/a.txtand the emptylib/appat build 2:cargo fmt --all -- --checkandRUST_MIN_STACK=8388608 cargo testpass.cargo clippy --all-targets --all-features -- -D warningson macOS gives 5dead_codeerrors insrc/utils/host_mounts.rs. They are onmaintoo. This change adds no warnings.