Properly detect if local file was successfully downloaded

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2017-11-21 18:35:58 +01:00
parent 164a81776e
commit 8976930e20
No known key found for this signature in database
GPG key ID: 00135ACBD90B28DD

View file

@ -193,9 +193,10 @@ gravity_Pull() {
patternBuffer=$(mktemp -p "/tmp" --suffix=".phgpb") patternBuffer=$(mktemp -p "/tmp" --suffix=".phgpb")
# Determine if $saveLocation has read permission # Determine if $saveLocation has read permission
if [[ -r "${saveLocation}" ]]; then if [[ -r "${saveLocation}" && $url != "file"* ]]; then
# Have curl determine if a remote file has been modified since last retrieval # Have curl determine if a remote file has been modified since last retrieval
# Uses "Last-Modified" header, which certain web servers do not provide (e.g: raw github urls) # Uses "Last-Modified" header, which certain web servers do not provide (e.g: raw github urls)
# Note: Don't do this for local files, always download them
heisenbergCompensator="-z ${saveLocation}" heisenbergCompensator="-z ${saveLocation}"
fi fi
@ -223,7 +224,12 @@ gravity_Pull() {
* ) echo -e "${OVER} ${CROSS} ${str} ${httpCode}";; * ) echo -e "${OVER} ${CROSS} ${str} ${httpCode}";;
esac;; esac;;
# Did we "download" a local file? # Did we "download" a local file?
"file"*) echo -e "${OVER} ${TICK} ${str} Retrieval successful"; success=true;; "file"*)
if [[ -s "${patternBuffer}" ]]; then
echo -e "${OVER} ${TICK} ${str} Retrieval successful"; success=true
else
echo -e "${OVER} ${CROSS} ${str} Not found"
fi;;
* ) echo -e "${OVER} ${CROSS} ${str} ${url} ${httpCode}";; * ) echo -e "${OVER} ${CROSS} ${str} ${url} ${httpCode}";;
esac esac
@ -237,7 +243,7 @@ gravity_Pull() {
gravity_ParseFileIntoDomains "${patternBuffer}" "${saveLocation}" gravity_ParseFileIntoDomains "${patternBuffer}" "${saveLocation}"
else else
# Fall back to previously cached list if $patternBuffer is empty # Fall back to previously cached list if $patternBuffer is empty
echo -e " ${INFO} ${COL_LIGHT_GREEN}Using previously cached list${COL_NC}" echo -e " ${INFO} Received empty file: ${COL_LIGHT_GREEN}using previously cached list${COL_NC}"
fi fi
else else
# Determine if cached list has read permission # Determine if cached list has read permission