Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o, Zac Medico <zmedico@g.o>, Zac Medico <zmedico@g.o>
Subject: Re: [gentoo-portage-dev] [PATCH 3/3] portage.dbapi.vartree: Support exclusions in INSTALL_MASK
Date: Sun, 12 Jun 2016 10:03:57
Message-Id: 703E0C62-3798-4F48-9E3A-CDAD9AEDBEA8@gentoo.org
In Reply to: Re: [gentoo-portage-dev] [PATCH 3/3] portage.dbapi.vartree: Support exclusions in INSTALL_MASK by Zac Medico
1 Dnia 12 czerwca 2016 11:43:35 CEST, Zac Medico <zmedico@g.o> napisał(a):
2 >On 06/12/2016 02:31 AM, Michał Górny wrote:
3 >> Dnia 12 czerwca 2016 11:20:36 CEST, Zac Medico <zmedico@g.o>
4 >napisał(a):
5 >>> On 05/21/2016 11:56 PM, Michał Górny wrote:
6 >>>> Allow INSTALL_MASK patterns to start with '-' to indicate that
7 >>>> a specific match is to be excluded from being masked. In this case,
8 >>>> the last matching pattern determines whether the file is actually
9 >>>> filtered out or kept.
10 >>>> ---
11 >>>> pym/portage/dbapi/vartree.py | 10 ++++++----
12 >>>> 1 file changed, 6 insertions(+), 4 deletions(-)
13 >>>>
14 >>>> diff --git a/pym/portage/dbapi/vartree.py
15 >>> b/pym/portage/dbapi/vartree.py
16 >>>> index 8e5ac43..d02d850 100644
17 >>>> --- a/pym/portage/dbapi/vartree.py
18 >>>> +++ b/pym/portage/dbapi/vartree.py
19 >>>> @@ -3690,19 +3690,21 @@ class dblink(object):
20 >>>> def _is_install_masked(self, relative_path):
21 >>>> ret = False
22 >>>> for pattern in self.settings.install_mask:
23 >>>> + # if pattern starts with -, possibly exclude this path
24 >>>> + pat_res = not pattern.startswith('-')
25 >>>> + if not pat_res:
26 >>>> + pattern = pattern[1:]
27 >>>> # absolute path pattern
28 >>>> if pattern.startswith('/'):
29 >>>> # match either exact path or one of parent dirs
30 >>>> # the latter is done via matching pattern/*
31 >>>> if (fnmatch.fnmatch(relative_path, pattern[1:])
32 >>>> or fnmatch.fnmatch(relative_path, pattern[1:] + '/*')):
33 >>>> - ret = True
34 >>>> - break
35 >>>> + ret = pat_res
36 >>>> # filename
37 >>>> else:
38 >>>> if fnmatch.fnmatch(os.path.basename(relative_path), pattern):
39 >>>> - ret = True
40 >>>> - break
41 >>>> + ret = pat_res
42 >>>> return ret
43 >>>>
44 >>>> def treewalk(self, srcroot, destroot, inforoot, myebuild,
45 >>> cleanup=0,
46 >>>>
47 >>>
48 >>> In order to implement this with pre-compiled patterns, we can use a
49 >>> separate regular expression to represent all of the exclusions.
50 >>
51 >> That won't work since exclusive and inclusive patterns can be
52 >stacked, and for this to work they are applied in order.
53 >>
54 >> E.g. /usr/foo -/usr/foo/bar /usr/foo/bar/baz
55 >>
56 >> Should remove all foo subdirectories except for bar, and also baz
57 >inside bar.
58 >
59 >Hmm, I suppose there could be an optimized implementation to handle
60 >INSTALL_MASK settings where there are no such ordering constraints.
61
62 Is this really worth the effort? I'm using the patch for a while and I/O's the bottleneck, not CPU. If you really insist on optimizing this, i guess we could precompile all patterns separately.
63
64
65 --
66 Best regards,
67 Michał Górny (by phone)

Replies