Skip to content

Commit

Permalink
Update sync helper script
Browse files Browse the repository at this point in the history
- Should fix partial files during uploads sometimes not copying fully
  • Loading branch information
Loki-101 authored Dec 11, 2024
1 parent 1bd12e3 commit f3fd81d
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions .helpers/listen.sh
Original file line number Diff line number Diff line change
@@ -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
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

0 comments on commit f3fd81d

Please sign in to comment.