Skip to content

Commit

Permalink
avoid uploading corrupted cache to S3
Browse files Browse the repository at this point in the history
  • Loading branch information
chirgjn committed Aug 9, 2024
1 parent bb703b7 commit cfe55cd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/backends/s3.bash
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,17 @@ function cache() {
TMP_FILE="$(mktemp)"
tar "${BK_TAR_ARGS[@]}" "${TMP_FILE}" ${TAR_TARGETS}
mv -f "${TMP_FILE}" "${TAR_FILE}"
aws s3 cp ${BK_CUSTOM_AWS_ARGS} "${TAR_FILE}" "s3://${BUCKET}/${TAR_FILE}"

if ! tar tf "${TAR_FILE}" &> /dev/null; then
rm -rf "${TAR_FILE}"
tar "${BK_TAR_ARGS[@]}" "${TMP_FILE}" ${TAR_TARGETS}
mv -f "${TMP_FILE}" "${TAR_FILE}"
fi
if ! tar tf "${TAR_FILE}" &> /dev/null; then
error "Error while packaging cache"
else
aws s3 cp ${BK_CUSTOM_AWS_ARGS} "${TAR_FILE}" "s3://${BUCKET}/${TAR_FILE}"
fi
fi
rm -f "${TAR_FILE}"
}

0 comments on commit cfe55cd

Please sign in to comment.