File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -121,18 +121,24 @@ function create_image_from_sdcard_rootfs() {
121121 declare -g ROOTFS_ARCHIVE_PATH=" "
122122 if [[ " ${rootfs_compression} " != " none" ]]; then
123123 ROOTFS_ARCHIVE_PATH=" ${FINALDEST} /${version} -rootfs.${archive_ext} "
124+ # Write under DESTIMG (cleanup-managed) and publish atomically on success —
125+ # otherwise a truncated archive from a failed tar/pv/compressor stage lingers
126+ # in FINALDEST and looks like a valid artifact.
127+ declare rootfs_archive_tmp=" ${DESTIMG} /${version} -rootfs.${archive_ext} "
124128 display_alert " Creating rootfs archive" " ${version} -rootfs.${archive_ext} " " info"
125129 # Subshell with pipefail so failures in tar/pv propagate (otherwise the
126130 # exit code of the final compressor stage hides truncation mid-archive).
127131 declare -a tar_excludes=(--exclude=' ./boot/*' --exclude=' ./dev/*' --exclude=' ./proc/*' --exclude=' ./run/*' --exclude=' ./tmp/*' --exclude=' ./sys/*' )
128132 [[ " ${INCLUDE_HOME_DIR:- no} " != " yes" ]] && tar_excludes+=(--exclude=' ./home/*' )
133+ rm -f " ${rootfs_archive_tmp} "
129134 (
130135 set -o pipefail
131136 tar cp --xattrs --directory=" $SDCARD /" " ${tar_excludes[@]} " . |
132137 pv -p -b -r -s " $( du -sb " $SDCARD " / | cut -f1) " \
133138 -N " $( logging_echo_prefix_for_pv " create_rootfs_archive" ) rootfs.${archive_ext} " |
134- ${archive_filter} > " ${ROOTFS_ARCHIVE_PATH } "
139+ ${archive_filter} > " ${rootfs_archive_tmp } "
135140 )
141+ run_host_command_logged mv -v " ${rootfs_archive_tmp} " " ${ROOTFS_ARCHIVE_PATH} "
136142 fi
137143
138144 # ROOTFS_EXPORT_DIR: when set, also rsync rootfs tree into this directory.
You can’t perform that action at this time.
0 commit comments