tree.sh: Delete files *before* updating hashes

The current logic deletes old project files e.g. sources,
but *after* updating the project hash.

This means that if a deletion fails, and the directory
is still there (e.g. src/coreboot/default/) afterward, it's
now a tainted archive, yet the hash has been updated, so
subsequent runs of the build system will cause unknown
errors.

This patch fixes that, by first copying the new hash to
a temporary file. *Then*, deletions are handled, and the
final hash file is updated afterward.

The code is now a bit more bloated as a result, but this will
reduce the risk of tainted sources being handled under fault
conditions.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2025-08-10 14:50:32 +01:00
parent d44c143846
commit 41945a2220
+9 -4
View File
@@ -177,10 +177,15 @@ delete_old_project_files()
{
project_up_to_date hash "$tree" badhash "$datadir" "$configdir/$tree" \
"$mdir" || x_ rm -Rf "src/$project/$tree" "elf/$project/$tree"; :
x_ cp "$xbtmp/new.hash" "$XBMK_CACHE/hash/$project$tree"
singletree "$project" || [ -z "$target" ] || [ "$target" = "$tree" ] \
|| project_up_to_date tghash "$target" badtghash \
singletree "$project" && return 0
[ -z "$target" ] && return 0
[ "$target" = "$tree" ] && return 0
project_up_to_date tghash "$target" badtghash \
"$configdir/$target" || x_ rm -Rf "elf/$project/$tree/$target"; :
x_ cp "$xbtmp/new.hash" "$XBMK_CACHE/tghash/$project$target"
}
project_up_to_date()
@@ -207,8 +212,8 @@ project_up_to_date()
[ -f "$XBMK_CACHE/$hashdir/$project$hashname" ] || \
eval "$badhashvar=\"y\""
printf "%s\n" "$hash" > "$XBMK_CACHE/$hashdir/$project$hashname" || \
err "!mk $XBMK_CACHE/$hashdir/$project$hashname"
printf "%s\n" "$hash" > "$xbtmp/new.hash" || \
err "!mkhash $xbtmp/new.hash ($hashdir $hashname $badhashvar)"
eval "[ \"\$$badhashvar\" = \"y\" ] && return 1"; :
}