Fix rare race condition for cache file

This commit is contained in:
Mark Kelly 2018-05-26 20:30:36 -04:00
commit a92fc5f553

View file

@ -50,7 +50,8 @@ ___update_cache() {
# Ensure that no more than one of these run at a given time # Ensure that no more than one of these run at a given time
if [ -x /usr/lib/update-notifier/apt-check ]; then if [ -x /usr/lib/update-notifier/apt-check ]; then
# If apt-check binary exists, use it # If apt-check binary exists, use it
flock -xn "$flock" /usr/lib/update-notifier/apt-check 2>&1 | awk '-F;' 'END { print $1, $2 }' >"$mycache" 2>/dev/null & # orig - flock -xn "$flock" /usr/lib/update-notifier/apt-check 2>&1 | awk '-F;' 'END { print $1, $2 }' >"$mycache" 2>/dev/null &
flock -xn "$flock" sh -c "(/usr/lib/update-notifier/apt-check 2>&1 | awk '-F;' 'END { print \$1, \$2 }' >\"${mycache}-x\" 2>/dev/null ; mv \"${mycache}-x\" \"$mycache\")" &
elif eval $BYOBU_TEST apt-get >/dev/null; then elif eval $BYOBU_TEST apt-get >/dev/null; then
# If apt-get exists, use it # If apt-get exists, use it
flock -xn "$flock" apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst >$mycache 2>/dev/null & flock -xn "$flock" apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst >$mycache 2>/dev/null &
@ -85,8 +86,19 @@ ___update_needed() {
[ ! -e "$mycache" ] && return 0 [ ! -e "$mycache" ] && return 0
if eval $BYOBU_TEST apt-get >/dev/null; then if eval $BYOBU_TEST apt-get >/dev/null; then
# Debian/ubuntu # Debian/ubuntu
[ "/var/lib/apt" -nt "$mycache" ] || [ "/var/lib/apt/lists" -nt "$mycache" ] # orig - [ "/var/lib/apt" -nt "$mycache" ] || [ "/var/lib/apt/lists" -nt "$mycache" ]
return $? # orig - return $?
d0=$(($(stat -c %Y $mycache 2>/dev/null)-5))
d1=$(stat -c %Y /var/lib/apt)
d2=$(stat -c %Y /var/lib/apt/lists)
d3=$(stat -c %Y /var/log/dpkg.log)
now=$(date +%s)
delta=$(($now-$d0))
if [ $d0 -lt 0 -o $d1 -ge $d0 -o $d2 -ge $d0 -o $d3 -ge $d0 -o $delta -ge 3605 ] ; then
return 0
else
return 1
fi
elif [ -e "/var/lib/PackageKit/transactions.db" ]; then elif [ -e "/var/lib/PackageKit/transactions.db" ]; then
[ "/var/lib/PackageKit/transactions.db" -nt "$mycache" ] [ "/var/lib/PackageKit/transactions.db" -nt "$mycache" ]
return $? return $?