1 |
commit: 0936d873aedccfb46ca4353c0b52f460287d6682 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Nov 13 02:11:07 2017 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Nov 14 03:14:19 2017 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=0936d873 |
7 |
|
8 |
vardbapi.removeFromContents: update NEEDED (bug 637284) |
9 |
|
10 |
When removing files from CONTENTS, also remove the corresponding |
11 |
lines from NEEDED, so that they do not corrupt LinkageMap data |
12 |
for preserve-libs. |
13 |
|
14 |
Bug: https://bugs.gentoo.org/637284 |
15 |
Reviewed-by: Manuel RĂ¼ger <mrueg <AT> gentoo.org> |
16 |
|
17 |
pym/portage/dbapi/vartree.py | 42 ++++++++++++++++++++++++++++++++++++++++-- |
18 |
1 file changed, 40 insertions(+), 2 deletions(-) |
19 |
|
20 |
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py |
21 |
index 04a40b732..b28b1c56c 100644 |
22 |
--- a/pym/portage/dbapi/vartree.py |
23 |
+++ b/pym/portage/dbapi/vartree.py |
24 |
@@ -39,6 +39,7 @@ portage.proxy.lazyimport.lazyimport(globals(), |
25 |
'portage.util._xattr:xattr', |
26 |
'portage.util._dyn_libs.PreservedLibsRegistry:PreservedLibsRegistry', |
27 |
'portage.util._dyn_libs.LinkageMapELF:LinkageMapELF@LinkageMap', |
28 |
+ 'portage.util._dyn_libs.NeededEntry:NeededEntry', |
29 |
'portage.util._async.SchedulerInterface:SchedulerInterface', |
30 |
'portage.util._eventloop.EventLoop:EventLoop', |
31 |
'portage.util._eventloop.global_event_loop:global_event_loop', |
32 |
@@ -1094,18 +1095,55 @@ class vardbapi(dbapi): |
33 |
removed += 1 |
34 |
|
35 |
if removed: |
36 |
- self.writeContentsToContentsFile(pkg, new_contents) |
37 |
+ # Also remove corresponding NEEDED lines, so that they do |
38 |
+ # no corrupt LinkageMap data for preserve-libs. |
39 |
+ needed_filename = os.path.join(pkg.dbdir, LinkageMap._needed_aux_key) |
40 |
+ new_needed = None |
41 |
+ try: |
42 |
+ with io.open(_unicode_encode(needed_filename, |
43 |
+ encoding=_encodings['fs'], errors='strict'), |
44 |
+ mode='r', encoding=_encodings['repo.content'], |
45 |
+ errors='replace') as f: |
46 |
+ needed_lines = f.readlines() |
47 |
+ except IOError as e: |
48 |
+ if e.errno not in (errno.ENOENT, errno.ESTALE): |
49 |
+ raise |
50 |
+ else: |
51 |
+ new_needed = [] |
52 |
+ for l in needed_lines: |
53 |
+ l = l.rstrip("\n") |
54 |
+ if not l: |
55 |
+ continue |
56 |
+ try: |
57 |
+ entry = NeededEntry.parse(needed_filename, l) |
58 |
+ except InvalidData as e: |
59 |
+ writemsg_level("\n%s\n\n" % (e,), |
60 |
+ level=logging.ERROR, noiselevel=-1) |
61 |
+ continue |
62 |
|
63 |
- def writeContentsToContentsFile(self, pkg, new_contents): |
64 |
+ filename = os.path.join(root, entry.filename.lstrip(os.sep)) |
65 |
+ if filename in new_contents: |
66 |
+ new_needed.append(entry) |
67 |
+ |
68 |
+ self.writeContentsToContentsFile(pkg, new_contents, new_needed=new_needed) |
69 |
+ |
70 |
+ def writeContentsToContentsFile(self, pkg, new_contents, new_needed=None): |
71 |
""" |
72 |
@param pkg: package to write contents file for |
73 |
@type pkg: dblink |
74 |
@param new_contents: contents to write to CONTENTS file |
75 |
@type new_contents: contents dictionary of the form |
76 |
{u'/path/to/file' : (contents_attribute 1, ...), ...} |
77 |
+ @param new_needed: new NEEDED entries |
78 |
+ @type new_needed: list of NeededEntry |
79 |
""" |
80 |
root = self.settings['ROOT'] |
81 |
self._bump_mtime(pkg.mycpv) |
82 |
+ if new_needed is not None: |
83 |
+ f = atomic_ofstream(os.path.join(pkg.dbdir, LinkageMap._needed_aux_key)) |
84 |
+ for entry in new_needed: |
85 |
+ f.write(_unicode(entry)) |
86 |
+ f.close() |
87 |
f = atomic_ofstream(os.path.join(pkg.dbdir, "CONTENTS")) |
88 |
write_contents(new_contents, root, f) |
89 |
f.close() |