- rm -rf ${CACHE_TMP}/cache
- mkdir -p ${CACHE_TMP}/cache
- echo "Downloading cach file ${BUILD_CACHE_URI}/${REMOTE_CACHE_ARCH_NAME} ..."
- set +e
- ${REMOTE_ACCESS_METHD} -o ${CACHE_TMP}/cache/${LOCAL_CACHE_ARCH_NAME}.tgz ${BUILD_CACHE_URI}/${REMOTE_CACHE_ARCH_NAME}.tgz
- rc=$?
- set -e
- if [ $rc -ne 0 ]; then
- echo "Remote cache does not exist, or is not accessible - a new cache will be built ..."
- POPULATE_CACHE=1
- else
- echo "Unpacking cache file ..."
- tar -C ${CACHE_TMP}/cache -xvf ${CACHE_TMP}/cache/${LOCAL_CACHE_ARCH_NAME}.tgz
- cp ${CACHE_TMP}/cache/cache/.versions ${BUILD_BASE}/.
- set +e
- make -C ${BUILD_BASE} validate-cache;
- rc=$?
- set -e
-
- if [ $rc -ne 0 ]; then
- echo "Cache invalid - a new cache will be built "
- POPULATE_CACHE=1
- else
- cp -rf ${CACHE_TMP}/cache/cache/. ${BUILD_BASE}
- fi
- rm -rf ${CACHE_TMP}/cache
- fi
+ rm -rf ${CACHE_TMP}/cache
+ mkdir -p ${CACHE_TMP}/cache
+ echo "Downloading cache archive ${BUILD_CACHE_URI}/${REMOTE_CACHE_ARCH_NAME} ..."
+ set +e
+ ${REMOTE_ACCESS_METHD} -o ${CACHE_TMP}/cache/${LOCAL_CACHE_ARCH_NAME}.tgz ${BUILD_CACHE_URI}/${REMOTE_CACHE_ARCH_NAME}.tgz
+ rc=$?
+ set -e
+ if [ $rc -ne 0 ]; then
+ echo "Remote cache does not exist, or is not accessible - a new cache will be built ..."
+ POPULATE_CACHE=1
+ else
+ echo "Unpacking cache archive ..."
+ set +e
+ tar -C ${CACHE_TMP}/cache -xvf ${CACHE_TMP}/cache/${LOCAL_CACHE_ARCH_NAME}.tgz
+ rc=$?
+ set -e
+ if [ $rc -ne 0 ]; then
+ echo "WARNING: The cache seems to be corrupt or has trailing garbage, will try to use brute force"
+ echo "Info about the cache below:"
+ set +e
+ file ${CACHE_TMP}/cache/${LOCAL_CACHE_ARCH_NAME}.tgz
+ tar -C ${CACHE_TMP}/cache -tvf ${CACHE_TMP}/cache/${LOCAL_CACHE_ARCH_NAME}.tgz
+ set -e
+ echo "Current time is: `date`"
+ set +e
+ pushd ${CACHE_TMP}/cache
+ gunzip -dcq ${CACHE_TMP}/cache/${LOCAL_CACHE_ARCH_NAME}.tgz | tar -xvf -
+ rc=$?
+ set -e
+ popd
+ if [ $rc -ne 0 ]; then
+ echo "ERROR: Not able to resolve the cache corruption"
+ POPULATE_CACHE=1
+ else
+ echo "The chache corruption was resolved"
+ cp ${CACHE_TMP}/cache/cache/.versions ${BUILD_BASE}/.
+ set +e
+ make -C ${BUILD_BASE} validate-cache;
+ rc=$?
+ set -e
+ if [ $rc -ne 0 ]; then
+ echo "Cache invalid - a new cache will be built "
+ POPULATE_CACHE=1
+ else
+ echo "Cache is up to date and will be used"
+ cp -rf ${CACHE_TMP}/cache/cache/. ${BUILD_BASE}
+ fi
+ fi
+ else
+ echo "Cache archive is intact"
+ cp ${CACHE_TMP}/cache/cache/.versions ${BUILD_BASE}/.
+ set +e
+ make -C ${BUILD_BASE} validate-cache;
+ rc=$?
+ set -e
+
+ if [ $rc -ne 0 ]; then
+ echo "Cache invalid - a new cache will be built "
+ POPULATE_CACHE=1
+ else
+ echo "Cache is up to date and will be used"
+ cp -rf ${CACHE_TMP}/cache/cache/. ${BUILD_BASE}
+ fi
+ fi
+ rm -rf ${CACHE_TMP}/cache
+ fi