Merge lp:~lasall/update-notifier/compare-verobj-id into lp:update-notifier/ubuntu

Proposed by Dominique Lasserre
Status: Needs review
Proposed branch: lp:~lasall/update-notifier/compare-verobj-id
Merge into: lp:update-notifier/ubuntu
Diff against target: 12 lines (+1/-1)
1 file modified
data/apt_check.py (+1/-1)
To merge this branch: bzr merge lp:~lasall/update-notifier/compare-verobj-id
Reviewer Review Type Date Requested Status
Brian Murray Needs Information
Michael Vogt Pending
Review via email: mp+114994@code.launchpad.net

Description of the change

Comparing apt_pkg.Version objects with == operator does not always work as expected. Use id method instead to compare unique integers.

To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

Could you provide some more details about how it does not always work as expected and why use .id will work better? Thanks in advance.

review: Needs Information
Revision history for this message
Dominique Lasserre (lasall) wrote :

I run into this issue that depcache.keep_count was one item higher than my own cache iterations with depcache.marked_keep (see following code snippet):

[...]
tmpkeep = []
for pkg in keep: # keep is a list with all depcache.marked_keep package objects
  ver = pkg.current_ver
  if ver is None:
    continue
  cand = depcache.get_candidate_ver(pkg)
  if not cand.id == ver.id: # version objects compared by id
    if cand == ver: # version objects compared with ==
      print(cand)
      print(ver)
    tmpkeep.append(pkg)
keep = tmpkeep
[...]

I get exactly one package object from this code snippet:
<apt_pkg.Version object: Pkg:'libexiv2-11' Ver:'0.22-2' Section:'libs' Arch:'amd64' Size:769732 ISize:2281472 Hash:30169 ID:103107 Priority:4>
<apt_pkg.Version object: Pkg:'libexiv2-11' Ver:'0.22-2' Section:'libs' Arch:'amd64' Size:0 ISize:2314240 Hash:62916 ID:219590 Priority:4>

$ apt-cache policy libexiv2-11
libexiv2-11:
  Installed: 0.22-2
  Candidate: 0.22-2
  Version table:
     0.22-2 0
        112 http://archive.ubuntu.com/ubuntu/ precise/main amd64 Packages
 *** 0.22-2 0
        100 /var/lib/dpkg/status

It took me a while to figure that out. I looked up how oher software (including update-notifier) implemented this piece of code and because update-notifier would run into same issue I did this merge request.

Unmerged revisions

722. By Dominique Lasserre

Compare unique ids instead of apt_pkg.Version objects with == operator.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/apt_check.py'
--- data/apt_check.py 2012-07-02 17:07:43 +0000
+++ data/apt_check.py 2012-07-14 19:35:23 +0000
@@ -124,7 +124,7 @@
124 # (workaround for ubuntu #7907)124 # (workaround for ubuntu #7907)
125 inst_ver = pkg.current_ver125 inst_ver = pkg.current_ver
126 cand_ver = depcache.get_candidate_ver(pkg)126 cand_ver = depcache.get_candidate_ver(pkg)
127 if cand_ver == inst_ver:127 if cand_ver.id == inst_ver.id:
128 continue128 continue
129129
130 # check for security upgrades130 # check for security upgrades

Subscribers

People subscribed via source and target branches

to all changes: