mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-21 05:53:22 -07:00
Fix rare race condition for cache file
This commit is contained in:
parent
cb9467a142
commit
a92fc5f553
1 changed files with 15 additions and 3 deletions
|
@ -50,7 +50,8 @@ ___update_cache() {
|
|||
# Ensure that no more than one of these run at a given time
|
||||
if [ -x /usr/lib/update-notifier/apt-check ]; then
|
||||
# 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
|
||||
# If apt-get exists, use it
|
||||
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
|
||||
if eval $BYOBU_TEST apt-get >/dev/null; then
|
||||
# Debian/ubuntu
|
||||
[ "/var/lib/apt" -nt "$mycache" ] || [ "/var/lib/apt/lists" -nt "$mycache" ]
|
||||
return $?
|
||||
# orig - [ "/var/lib/apt" -nt "$mycache" ] || [ "/var/lib/apt/lists" -nt "$mycache" ]
|
||||
# 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
|
||||
[ "/var/lib/PackageKit/transactions.db" -nt "$mycache" ]
|
||||
return $?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue