Comment 7 for bug 1604750

Revision history for this message
James Sinton (jksinton) wrote :

The bug is definitely is caused by the modification time check in updated_needed(): [ "/var/lib/apt" -nt "$mycache" ] || [ "/var/lib/apt/lists" -nt "$mycache" ].

The problem is that during an upgrade by running apt-get upgrade, /var/lib/apt is modified, but not upon completion of the upgrade. So byobu triggers an update to the cache during the upgrade, but not afterwards. See the stats of the files after the upgrade I used to verify this situation:

$stat /var/lib/apt/lists
  File: '/var/lib/apt/lists'
  Size: 20480 Blocks: 40 IO Block: 4096 directory
Device: 846h/2118d Inode: 661369 Links: 3
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-12-13 12:30:47.271921285 -0600
Modify: 2016-12-13 12:30:47.263921961 -0600
Change: 2016-12-13 12:30:47.263921961 -0600
 Birth: -

$ stat /var/lib/apt
  File: '/var/lib/apt'
  Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 846h/2118d Inode: 530070 Links: 6
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-12-13 12:35:11.761565067 -0600
Modify: 2016-12-13 13:05:24.564724270 -0600
Change: 2016-12-13 13:05:24.564724270 -0600
 Birth: -

Stat of updates_available:
$stat /dev/shm/byobu-user-XXXXXXXX/cache.screen/updates-available
  File: '/dev/shm/byobu-user-XXXXXXXX/cache.screen/updates-available'
  Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 15h/21d Inode: 29 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ james) Gid: ( 1000/ james)
Access: 2016-12-13 13:06:01.117645947 -0600
Modify: 2016-12-13 13:05:30.820197467 -0600
Change: 2016-12-13 13:05:30.820197467 -0600
 Birth: -

As shown above, the updates_available file has a more recent modification time than /var/lib/apt and /var/lib/apt/lists. So we need to find a file that indicates the upgrade is complete to tell byobu to update the cache file. I chose /var/log/dpkg.log, which works. A caveat is that monitoring /var/log/dpkg.log may trigger updates to the cache for any activity logged to dpkg, which includes installations, not just upgrades.

My implementation is this:
if $BYOBU_TEST apt-get >/dev/null; then
                # Debian/ubuntu
                [ "/var/lib/apt" -nt "$mycache" ] || [ "/var/lib/apt/lists" -nt "$mycache" ] || [ "/var/log/dpkg.log" -nt "$mycache" ]
                        return $?

Regards,
James