Gentoo Archives: gentoo-portage-dev

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