From 4f5c2a3a906bdd66b5f30a06c7a872c4b39925cb Mon Sep 17 00:00:00 2001 From: Alex Palaistras Date: Sun, 12 Sep 2021 21:53:37 +0100 Subject: [PATCH] hooks/post-merge: Set file timestamps for updates Partial updates require that source files have appropriate timestamps, which Git does not set in any special way by default. Thus, before attempting to update files in-place, we set source timestamps based on last commit time, which is the effective update time in any case. --- hooks/post-merge | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/hooks/post-merge b/hooks/post-merge index 5643e85..d61a26d 100755 --- a/hooks/post-merge +++ b/hooks/post-merge @@ -7,6 +7,7 @@ # The script assumes write access to host directories, and a CoreOS host. Don't run on other systems! set -euo pipefail +shopt -s globstar # Global configuration variables. TEMP_CONFIG_PATH="$(git -C "$(dirname "$0")" rev-parse --show-toplevel)" @@ -25,10 +26,17 @@ function sync-coreos-config() { fi # Remove files that only exist in local configuration. - for n in $(comm -23 <(cd "$path"; find . | sort) <(cd "$dir"; find . | sort)); do - rm --verbose --recursive --force "$(realpath --quiet "$path/$n")" + for f in $(comm -23 <(cd "$path"; find . | sort) <(cd "$dir"; find . | sort)); do + rm --verbose --recursive --force "$(realpath --quiet "$path/$f")" done + # Update timestamp for temporary file to match last commit time, in order to ensure + # correct partial updates. + for f in "$dir/"**; do + touch --date="$(git -C "$TEMP_CONFIG_PATH" log -n 1 --pretty=format:%cd --date=iso --date-order -- "$f")" -- "$f" + done + + # Copy files from temporary directory to host configuration directory. cp --verbose --recursive --update --target-directory "$path" "$dir"/* echo "done." done @@ -36,8 +44,8 @@ function sync-coreos-config() { # Synchronize systemd service files from CoreOS home-server configuration. function sync-systemd-services() { - local dest local result=1 + local dest # Copy service files if newer than destination. for src in "$HOST_CONFIG_PATH"/*/systemd/*; do