Merge lp:~brian-murray/apport/bug-1336062 into lp:~apport-hackers/apport/trunk

Proposed by Brian Murray
Status: Merged
Merged at revision: 2818
Proposed branch: lp:~brian-murray/apport/bug-1336062
Merge into: lp:~apport-hackers/apport/trunk
Diff against target: 90 lines (+31/-29)
2 files modified
backends/packaging-apt-dpkg.py (+29/-29)
test/test_backend_apt_dpkg.py (+2/-0)
To merge this branch: bzr merge lp:~brian-murray/apport/bug-1336062
Reviewer Review Type Date Requested Status
Martin Pitt (community) Approve
Review via email: mp+226380@code.launchpad.net

Description of the change

This is pretty well documented in the attached bug report. I've chosen to test this by pretending that '/bin/true' is provided by mypackage. If we are using the cache from the sandbox then the test will pass, if not the test will fail with the following message.

 $ PYTHON=python3 test/run backend_apt_dpkg.test_get_file_package_uninstalled
Testing local source tree.
Running pep8...
Running pyflakes...
--- Testing backend_apt_dpkg.test_get_file_package_uninstalled ---
test_get_file_package_uninstalled (__main__.T)
get_file_package() on uninstalled packages. ... FAIL

======================================================================
FAIL: test_get_file_package_uninstalled (__main__.T)
get_file_package() on uninstalled packages.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test/test_backend_apt_dpkg.py", line 230, in test_get_file_package_uninstalled
    self.assertEqual(impl.get_file_package('/bin/true', True, cache_dir), 'mypackage')
AssertionError: 'coreutils' != 'mypackage'
- coreutils
+ mypackage

----------------------------------------------------------------------
Ran 1 test in 4.107s

FAILED (failures=1)

To post a comment you must log in.
Revision history for this message
Martin Pitt (pitti) wrote :

Thanks Brian, nice catch! I un-indented the moved code block again (as "return" doesn't need an else branch) to make the diff easier to read.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'backends/packaging-apt-dpkg.py'
2--- backends/packaging-apt-dpkg.py 2014-07-02 06:31:13 +0000
3+++ backends/packaging-apt-dpkg.py 2014-07-10 21:01:17 +0000
4@@ -336,38 +336,38 @@
5 Also, release and arch can be set to a foreign release/architecture
6 instead of the one from the current system.
7 '''
8- # check if the file is a diversion
9- dpkg = subprocess.Popen(['dpkg-divert', '--list', file],
10- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
11- out = dpkg.communicate()[0].decode('UTF-8')
12- if dpkg.returncode == 0 and out:
13- pkg = out.split()[-1]
14- if pkg != 'hardening-wrapper':
15- return pkg
16-
17- fname = os.path.splitext(os.path.basename(file))[0].lower()
18-
19- all_lists = []
20- likely_lists = []
21- for f in glob.glob('/var/lib/dpkg/info/*.list'):
22- p = os.path.splitext(os.path.basename(f))[0].lower().split(':')[0]
23- if p in fname or fname in p:
24- likely_lists.append(f)
25- else:
26- all_lists.append(f)
27-
28- # first check the likely packages
29- match = self.__fgrep_files(file, likely_lists)
30- if not match:
31- match = self.__fgrep_files(file, all_lists)
32-
33- if match:
34- return os.path.splitext(os.path.basename(match))[0].split(':')[0]
35-
36 if uninstalled:
37 return self._search_contents(file, map_cachedir, release, arch)
38 else:
39- return None
40+ # check if the file is a diversion
41+ dpkg = subprocess.Popen(['dpkg-divert', '--list', file],
42+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
43+ out = dpkg.communicate()[0].decode('UTF-8')
44+ if dpkg.returncode == 0 and out:
45+ pkg = out.split()[-1]
46+ if pkg != 'hardening-wrapper':
47+ return pkg
48+
49+ fname = os.path.splitext(os.path.basename(file))[0].lower()
50+
51+ all_lists = []
52+ likely_lists = []
53+ for f in glob.glob('/var/lib/dpkg/info/*.list'):
54+ p = os.path.splitext(os.path.basename(f))[0].lower().split(':')[0]
55+ if p in fname or fname in p:
56+ likely_lists.append(f)
57+ else:
58+ all_lists.append(f)
59+
60+ # first check the likely packages
61+ match = self.__fgrep_files(file, likely_lists)
62+ if not match:
63+ match = self.__fgrep_files(file, all_lists)
64+
65+ if match:
66+ return os.path.splitext(os.path.basename(match))[0].split(':')[0]
67+
68+ return None
69
70 @classmethod
71 def get_system_architecture(klass):
72
73=== modified file 'test/test_backend_apt_dpkg.py'
74--- test/test_backend_apt_dpkg.py 2014-04-30 14:27:45 +0000
75+++ test/test_backend_apt_dpkg.py 2014-07-10 21:01:17 +0000
76@@ -187,6 +187,7 @@
77 usr/bin/frobnicate foo/frob
78 usr/bin/frob foo/frob-utils
79 bo/gu/s na/mypackage
80+bin/true na/mypackage
81 ''')
82
83 # test Contents.gz for -updates pocket
84@@ -226,6 +227,7 @@
85
86 # valid cache, should not need to access the mirror
87 impl.set_mirror('file:///foo/nonexisting')
88+ self.assertEqual(impl.get_file_package('/bin/true', True, cache_dir), 'mypackage')
89 self.assertEqual(impl.get_file_package('/bo/gu/s', True, cache_dir), 'mypackage')
90 self.assertEqual(impl.get_file_package('/lib/libnew.so.5', True, cache_dir), 'libnew5')
91

Subscribers

People subscribed via source and target branches