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

Proposed by Dominique Lasserre on 2012-07-14
Status: Needs review
Proposed branch: lp:~lasall/update-notifier/compare-verobj-id
Merge into: lp:update-notifier
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 2012-07-14 Needs Information on 2012-07-18
Michael Vogt 2015-05-01 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.
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
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 on 2012-07-14

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
1=== modified file 'data/apt_check.py'
2--- data/apt_check.py 2012-07-02 17:07:43 +0000
3+++ data/apt_check.py 2012-07-14 19:35:23 +0000
4@@ -124,7 +124,7 @@
5 # (workaround for ubuntu #7907)
6 inst_ver = pkg.current_ver
7 cand_ver = depcache.get_candidate_ver(pkg)
8- if cand_ver == inst_ver:
9+ if cand_ver.id == inst_ver.id:
10 continue
11
12 # check for security upgrades

Subscribers

People subscribed via source and target branches

to all changes: