commit 77a603a904087dd9fd3350da029f279f076e4f4b
parent 9f596550ca47071fe31b03e4ab27e08c60b65f71
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 31 Jan 2016 15:31:17 +0100

sfeed_update: fix issue with merging failed feeds

When fetching a feed failed and its temporary file was stored (filesize=0)
it would still be merged with the (possible) old file. This updated the
modification time which would be used in the next poll (If-Modified-Since).

The solution is to check if the file is non-empty and only then merge, this
is still not 100% fool-proof, but much better.

Diffstat:
Msfeed_update | 19+++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/sfeed_update b/sfeed_update @@ -78,14 +78,17 @@ feed() { # get new data and merge with old. sfeedfilenew="${sfeedpath}/${name}.new" - # if file exists, merge - if [ -e "${sfeedfile}" ]; then - merge "${sfeedfile}" "${tmpfeedfile}" > "${sfeedfilenew}" - # overwrite old file with updated file - mv "${sfeedfilenew}" "${sfeedfile}" - else - # else just copy - mv "${tmpfeedfile}" "${sfeedfile}" + # new feed data is non-empty. + if [ -s "${tmpfeedfile}" ]; then + # if file exists, merge + if [ -e "${sfeedfile}" ]; then + merge "${sfeedfile}" "${tmpfeedfile}" > "${sfeedfilenew}" + # overwrite old file with updated file + mv "${sfeedfilenew}" "${sfeedfile}" + else + # else just copy + mv "${tmpfeedfile}" "${sfeedfile}" + fi fi) & }