[Fix] roomote upgrade prints spurious "tags_file: unbound variable" after completion - #5
Conversation
|
No new code issues found, and the previously flagged edge case is resolved. See task The new commit guards the
|
|
Thank you for your contribution! Before we can merge this pull request, we need you to sign our Contributor License Agreement. You can sign it by posting the comment below. I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
|
Fixed the The trap 'rm -f "$tags_file" "$images_file"; [ -n "$keep_file" ] && rm -f "$keep_file" "${keep_file}.dedup"; trap - RETURN' RETURNSo when Verified: reproduced the hazard against the pre-guard trap (a planted |
What changed
Fixed a spurious error printed after
sudo roomote upgradefinishes:The upgrade itself always succeeded — this line fired afterward, during image-retention cleanup. In
prune_roomote_images, a nestedcleanup_prune_roomote_imagesfunction was registered as a bashRETURNtrap and also called explicitly at the end of the function. bashRETURNtraps are dynamically scoped, sotrap - RETURNissued from inside the nested cleanup helper did not clear the trap inprune_roomote_images's own scope. The trap re-fired when an outer caller (cmd_upgrade) returned, by which point the function'slocalvariables (tags_file,keep_file,images_file) were already gone — and withset -uin effect, referencing them aborted with "unbound variable."The nested cleanup function is replaced with a single self-clearing inline
RETURNtrap:The trailing
trap - RETURNruns inside the trap handler (i.e. inprune_roomote_images's own frame at return time), so it clears the trap there and prevents it from propagating to outer callers. The redundant explicit cleanup call at the end of the function is removed; theRETURNtrap now owns cleanup on both normal completion and early-return (|| return) paths.The
.dedupremoval is guarded with[ -n "$keep_file" ]so that on the narrow early-return window wherekeep_file'smktempfails right aftertags_filesucceeds,keep_fileis still empty and the trap does not expand${keep_file}.dedupto.dedupand delete an unrelated.dedupfile in the current working directory.tags_fileandimages_fileare removed unconditionally becauserm -f ""is a harmless no-op (verified). This restores theif [ -n "$keep_file" ]guard that the original nested cleanup helper had.Why this change was made
The trailing error made successful upgrades look failed, which is alarming for operators and could mask a real failure that follows it. The
.dedupguard closes a review-flagged edge case where a failedmktempon the early-return path could have deleted an unrelated file in the deployment working directory. The locals are pre-initialized to''on theirlocaldeclaration line, so the inline trap body is safe underset -ueven on early-return paths where not every temp file has been created yet.Impact
roomote upgradeno longer prints a spurious "unbound variable" error after completing, and a failedkeep_filemktempon the early-return path cannot delete an unrelated.dedupfile in the current working directory. Temp-file cleanup behavior is preserved on both the normal-completion path and every|| returnearly-exit path insideprune_roomote_images; theRETURNtrap fires once on function return and removestags_file,images_file, and (whenkeep_fileis set)keep_fileand${keep_file}.dedup. No user-facing behavior changes beyond removing the misleading error and closing the edge case.