Package: lsb
Version: 3.1-23.1
Severity: normal
Tags: patch

Lsb_release code tries first to determine the system's version based on APT's
policy ('apt-show policy') and, if it fails, it tries to obtain the
information from /etc/debian_version. This behaviour, I guess, was introduced
due to #341231.

The changelog in 3.0-15 said that /etc/debian_version has priority, but that
is not true.

lsb_release will not work in this scenario:

1.- A user installed the oldstable release ('X' currently)
2.- In preparation for an upgrade, he changes his sources.list to point to
    the next release ('Y'). 
3.- The sysadmin run 'apt-get update' to get APT to reread the sources.list
4.- The sysadmin has doubts about the upgrade and does NOT upgrade the
    system

In this situation, lsb_release will just pickup the first entry it parsed
from 'apt-show policy' (sorted, by name?). Under some circunstances, in the
above case it could be 'Y' instead of 'X' even though the system has *not*
been upgraded.


IMHO lsb_release should honor the contents of /etc/debian_version and, if the
contents refer to testing/unstable (i.e. not numeric) try to determine the
release based on policy.

Attached is a patch that changes it behaviour so that it will only try to
check APT's policy if it trying to distinguish between testing/unstable (or
'lenny/sid', or whatever). It also speeds up lsb_release a little bit.

Regards

Javier
--- lsb_release.orig	2007-06-01 18:08:23.000000000 +0200
+++ lsb_release	2007-06-01 23:41:16.000000000 +0200
@@ -160,8 +160,26 @@
 
     distinfo['DESCRIPTION'] = '%(ID)s %(OS)s' % distinfo
 
+    if os.path.exists('/etc/debian_version'):
+        release = open('/etc/debian_version').read().strip()
+        if not release[0:1].isalpha():
+            # /etc/debian_version should be numeric
+            codename = lookup_codename(release, 'n/a')
+            distinfo.update({ 'RELEASE' : release, 'CODENAME' : codename })
+        else:
+            distinfo['RELEASE'] = release
+            distinfo['CODENAME'] = None
+
+    # Only use apt information if we did not get the proper information
+    # from /etc/debian_version or if we don't have a codename
+    # (which will happen if /etc/debian_version does not contain a
+    # number but some text like 'testing/unstable' or 'lenny/sid')
+    #
+    # This is slightly faster and less error prone in case the user
+    # has an entry in his /etc/apt/sources.list but has not actually
+    # upgraded the system.
     rinfo = guess_release_from_apt()
-    if rinfo:
+    if rinfo and not distinfo['CODENAME']:
         release = rinfo.get('version')
         if release:
             codename = lookup_codename(release, 'n/a')
@@ -173,14 +191,6 @@
             else:
                 codename = 'sid'
         distinfo.update({ 'RELEASE' : release, 'CODENAME' : codename })
-    elif os.path.exists('/etc/debian_version'):
-        release = open('/etc/debian_version').read().strip()
-        if not release[0:1].isalpha():
-            # /etc/debian_version should be numeric
-            codename = lookup_codename(release, 'n/a')
-            distinfo.update({ 'RELEASE' : release, 'CODENAME' : codename })
-        else:
-            distinfo['RELEASE'] = release
 
     if 'RELEASE' in distinfo:
         distinfo['DESCRIPTION'] += ' %(RELEASE)s' % distinfo

Reply via email to