From 04bc16e0867d0a19ba803570852610b63743c3f6 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 8 Oct 2023 16:32:15 -0700 Subject: [PATCH] copy_buildsync: fix corner cases for targets changing Signed-off-by: Robin H. Johnson --- scripts/copy_buildsync.sh | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/scripts/copy_buildsync.sh b/scripts/copy_buildsync.sh index 9da5893d..71e890d9 100755 --- a/scripts/copy_buildsync.sh +++ b/scripts/copy_buildsync.sh @@ -209,15 +209,42 @@ process_arch() { # Link the files for a given variant into a current-${v}/ directory. # If it's an old link, remove to convert to directory. if test -L "current-$v" ; then rm "current-$v" ; fi - mkdir -p "current-$v" + + # If there is a file here, something went wrong. + if ! mkdir -p "current-$v" ; then + echo "$ARCH: could not mkdir current-${v}" 1>&2 + continue + fi # Remove old links in the directory. find "current-$v" -type l ! -name "$f" ! -name "${variant_date}*" # install new links - # do NOT use -f here, we do not want to override the existing files. - # this will ensure the mtime of the links does not change in most cases. - ( cd "current-$v" && ln -s --target-directory=. "../${variant_path}"* ) + # do NOT unconditionally use -f here, we do not want to override the + # existing files. this will ensure the mtime of the links does not change + # in most cases. + ( + # shellcheck disable=SC2164 # error-checked above + cd "current-$v" + for variant_file in "../${variant_path}"* ; do + doit=0 + # If it doesn't exist, add it. + if [[ ! -e "$variant_file" ]]; then + doit=1 + ln -s -t . "../${variant_path}" + else + # If it does exist, check carefully to see if anything is different + # Does it point to somewhere else? + # Is the target newer? + # If those are true, also bump the symlink. + vfb=$(basename "$variant_file") + vft=$(readlink -f "$vfb") + [[ "$vft" != "$(readlink -f "$variant_file")" ]] && doit=1 + [[ "$vfb" -nt "$vft" ]] && doit=1 + fi + [[ $doit -eq 1 ]] && ln -sf -t . "../${variant_file}" + done + ) # Update keepfile echo "${variant_path}" | sed -e 's,/.*,,g' -e 's,^,/,g' -e 's,$,$,g' >>"${keepfile_tmp}"