From 2b77ac480dd7a349706c50078df8dd63c4ee9a07 Mon Sep 17 00:00:00 2001 From: Chirag Jain Date: Fri, 9 Aug 2024 23:22:27 +0530 Subject: [PATCH] avoid uploading corrupted cache to S3 --- lib/backends/s3.bash | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/backends/s3.bash b/lib/backends/s3.bash index bd89553..f1020d6 100644 --- a/lib/backends/s3.bash +++ b/lib/backends/s3.bash @@ -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}" }