Use http code to check object in lookaside cache

Currently, it only checks the size of the http object returned but it
may happen that the size of the 404 error page match the size of the
tarball. You may think this is a corner case we'll never hit... well, we
hit it, :)

This patch it's adding a check based on the http code, so to give it as
already uploaded we need it to return 200 code and match the actual
size.
This commit is contained in:
Alfredo Moralejo 2021-10-26 10:17:32 +02:00
parent b045956f51
commit 510f1aa0bc

View file

@ -80,8 +80,9 @@ checksum=$(sha1sum ${file}|awk '{print $1}')
f_log "Checking if file already uploaded"
local_size=$(stat -c %s ${file})
http_code=$(curl -s -o /dev/null -w "%{http_code}" ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum})
remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r')
if [ "$local_size" -eq "$remote_size" ] ; then
if [ "$http_code" -eq 200 ] && [ "$local_size" -eq "$remote_size" ] ; then
f_log "File already uploaded"
exit 3
fi