From 41945a222005d94e0e51adb1ba8ceb869b110bae Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 10 Aug 2025 14:50:32 +0100 Subject: 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 --- include/tree.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/tree.sh b/include/tree.sh index ef1e4caa..5edddf23 100644 --- a/include/tree.sh +++ b/include/tree.sh @@ -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"; : } -- cgit v1.2.1