Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(backup): stop deleting good archives with a long member list
Yudhi Armyndharis0b697aec3f0d
diff --git a/scripts/backup.sh b/scripts/backup.shindex e1012938e..1840e928a 100755--- a/scripts/backup.sh+++ b/scripts/backup.sh@@ -292,10 +292,12 @@ ARCHIVE_LIST="$(tar -tzf "$ARCHIVE")"# Min-content check on the finished archive: every configured database must be present. If not,# delete the defective archive and fail — leaving it on disk invites a restore into a fresh-empty-# install (new API keys, new master key) reported as success.+# install (new API keys, new master key) reported as success. grep reads a here-string, not a pipe: a+# grep -q that matches early stops reading, and on a listing larger than the pipe buffer the broken pipe+# made pipefail report a member that is there as missing.MISSING_MEMBERS=""for member in "${REQUIRED_MEMBERS[@]}"; do- if ! printf '%s\n' "$ARCHIVE_LIST" | grep -qxF "$member"; then+ if ! grep -qxF "$member" <<<"$ARCHIVE_LIST"; thenMISSING_MEMBERS="$MISSING_MEMBERS $member"fidonediff --git a/scripts/smoke-test-backup-restore.sh b/scripts/smoke-test-backup-restore.shindex 3a5d38b62..fafbd36a9 100755--- a/scripts/smoke-test-backup-restore.sh+++ b/scripts/smoke-test-backup-restore.sh@@ -46,6 +46,7 @@# (ad) a file an engine deletes during the sessions/ or baileys/ copy is noted instead of failing the# backup, a file the app deletes during the media or plugin copies is logged, and any other cp# error still fails it, however long its output and whatever the host's locale+# (ae) the min-content check passes an archive whose listing outgrows a pipe buffer## Usage: ./scripts/smoke-test-backup-restore.sh# Requires: bash, tar, node (restore.sh path resolution). sqlite3 is optional (see (c) and (k)).@@ -1329,5 +1330,35 @@ if [ "$RC_AD" -eq 0 ] || ! grep -q 'Permission denied' <<<"$OUT_AD" ||fipass "(ad) a vanished engine file is noted, a vanished media or plugin file logged, other cp errors fatal"+echo ""+echo "==> (ae) the min-content check passes an archive whose listing outgrows a pipe buffer"+# A whatsapp-web.js profile alone lists thousands of members. A grep -q that matched a required member+# early and stopped reading broke the pipe feeding it, and pipefail turned the match into "missing", so a+# good archive was deleted. The shim tar pads the listing after the real members, past a pipe buffer.+AE="$WORK/ae"+mkdir -p "$AE/data" "$AE/shim"+make_fixture "$AE/data/main.sqlite" "echo2-main"+make_fixture "$AE/data/openwa.sqlite" "echo2-data"+cat >"$AE/shim/tar" <<SHIM+#!/bin/sh+$(command -v tar) "\$@" || exit+if [ "\$1" = -tzf ]; then+ i=0+ while [ "\$i" -lt 20000 ]; do+ echo "./sessions/session-s1/Default/Cache/Cache_Data/padding-\$i"+ i=\$((i + 1))+ done+fi+SHIM+chmod +x "$AE/shim/tar"+set +e+OUT_AE="$(cd "$AE" && PATH="$AE/shim:$PATH" BACKUP_DIR="$AE/out" "$BACKUP" 2>&1)"+RC_AE=$?+set -e+if [ "$RC_AE" -ne 0 ] || [ -z "$(ls "$AE"/out/openwa-backup-*.tar.gz 2>/dev/null)" ]; then+ fail "(ae) a long archive listing failed the min-content check: $(grep -v padding- <<<"$OUT_AE")"+fi+pass "(ae) the min-content check reads the whole listing"+echo ""echo "All smoke tests passed!"