From f3fd81d0094024d93e07d15523eb6f368fa17030 Mon Sep 17 00:00:00 2001 From: Loki <59907407+Loki-101@users.noreply.github.com> Date: Tue, 10 Dec 2024 18:02:50 -0800 Subject: [PATCH] Update sync helper script - Should fix partial files during uploads sometimes not copying fully --- .helpers/listen.sh | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/.helpers/listen.sh b/.helpers/listen.sh index 639afad..95861a2 100644 --- a/.helpers/listen.sh +++ b/.helpers/listen.sh @@ -1,8 +1,35 @@ -#!/bin/sh -# Initial sync on startup to ensure /app is up to date with /blueprint_extensions -rsync -av --exclude=".blueprint" --include="*.blueprint*" --exclude="*" --delete /blueprint_extensions/ /app/ +#!/bin/bash +set -euo pipefail -# Continuously watch for file changes in /blueprint_extensions -while inotifywait -r -e create,delete,modify,move --include=".*\\.blueprint$" /blueprint_extensions; do - rsync -av --exclude=".blueprint" --include="*.blueprint*" --exclude="*" --delete /blueprint_extensions/ /app/ -done \ No newline at end of file +trap 'echo "Interrupted"; exit 1' INT TERM + +# Initial sync +rsync -av --exclude=".blueprint" --include="*.blueprint*" --exclude="*" --delete "/blueprint_extensions/" "/app/" + +# Continuous monitor task +inotifywait -m -q \ + -e close_write,delete,moved_to,moved_from \ + --format '%e %w%f' \ + "/blueprint_extensions/" | +while read -r event filepath; do + case "$filepath" in + *.blueprint) + case "$event" in + CLOSE_WRITE,CLOSE|MOVED_TO) + if ! cp "$filepath" "/app/$(basename "$filepath")"; then + echo "Error copying: $filepath" >&2 + else + echo "Updated: $filepath" + fi + ;; + DELETE|MOVED_FROM) + if ! rm -f "/app/$(basename "$filepath")"; then + echo "Error removing: $filepath" >&2 + else + echo "Removed: $filepath" + fi + ;; + esac + ;; + esac +done