Skip to content

Commit 08fd6ca

Browse files
committed
Avoid truncation issues
When WORKING_SNAPSHOT equals SNAPSHOT_PATH tee truncates SNAPSHOT_PATH. Creating a temp file for WORKING_SNAPSHOT fixes this.
1 parent 3953fa0 commit 08fd6ca

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

hack/reduce-snapshot.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ set -o pipefail
3232

3333
# Make sure to move snapshot contents to the WORKING_SNAPSHOT location. Then allow jq to
3434
# work with it there. This avoids having to read SNAPSHOT to memory.
35+
# Always use a temp file for WORKING_SNAPSHOT to avoid truncation issues when writing
36+
# the final output to SNAPSHOT_PATH (which may be the same file as SNAPSHOT).
3537

38+
WORKING_SNAPSHOT="$(mktemp "${HOME:-/tmp}/snapshot.XXXXXX")"
3639
if [[ -f "$SNAPSHOT" ]]; then
37-
WORKING_SNAPSHOT="$SNAPSHOT"
40+
cp "$SNAPSHOT" "$WORKING_SNAPSHOT"
3841
else
39-
WORKING_SNAPSHOT="$(mktemp "${HOME:-/tmp}/snapshot.XXXXXX")"
4042
printf "%s" "$SNAPSHOT" > "$WORKING_SNAPSHOT"
4143
fi
44+
4245
jq empty "$WORKING_SNAPSHOT" || { echo "JSON is invalid"; exit 1; }
4346

4447
echo "Single Component mode? ${SINGLE_COMPONENT}"

0 commit comments

Comments
 (0)