Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o, "Michał Górny" <mgorny@g.o>
Subject: Re: [gentoo-portage-dev] [PATCH v2] FreeBSD: use os.*chflags() instead of calling external tool
Date: Thu, 22 Feb 2018 19:10:17
Message-Id: d5142c0c-6ee6-3781-493c-6f76fbad6912@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH v2] FreeBSD: use os.*chflags() instead of calling external tool by "Michał Górny"
1 On 02/22/2018 11:06 AM, Michał Górny wrote:
2 > Use os.chflags() and os.lchflags() built-in functions instead of calling
3 > external 'chflags' tool on FreeBSD. This fixes major performance
4 > problems Portage has on FreeBSD.
5 >
6 > Bug: https://bugs.gentoo.org/648432
7 > ---
8 > pym/portage/__init__.py | 50 +++----------------------------------------------
9 > 1 file changed, 3 insertions(+), 47 deletions(-)
10 >
11 > diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
12 > index 0e036b12e..99f3f98ac 100644
13 > --- a/pym/portage/__init__.py
14 > +++ b/pym/portage/__init__.py
15 > @@ -419,54 +419,10 @@ def _shell_quote(s):
16 > bsd_chflags = None
17 >
18 > if platform.system() in ('FreeBSD',):
19 > -
20 > + # TODO: remove this class?
21 > class bsd_chflags(object):
22 > -
23 > - @classmethod
24 > - def chflags(cls, path, flags, opts=""):
25 > - cmd = ['chflags']
26 > - if opts:
27 > - cmd.append(opts)
28 > - cmd.append('%o' % (flags,))
29 > - cmd.append(path)
30 > -
31 > - if sys.hexversion < 0x3020000 and sys.hexversion >= 0x3000000:
32 > - # Python 3.1 _execvp throws TypeError for non-absolute executable
33 > - # path passed as bytes (see https://bugs.python.org/issue8513).
34 > - fullname = process.find_binary(cmd[0])
35 > - if fullname is None:
36 > - raise exception.CommandNotFound(cmd[0])
37 > - cmd[0] = fullname
38 > -
39 > - encoding = _encodings['fs']
40 > - cmd = [_unicode_encode(x, encoding=encoding, errors='strict')
41 > - for x in cmd]
42 > - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
43 > - stderr=subprocess.STDOUT)
44 > - output = proc.communicate()[0]
45 > - status = proc.wait()
46 > - if os.WIFEXITED(status) and os.WEXITSTATUS(status) == os.EX_OK:
47 > - return
48 > - # Try to generate an ENOENT error if appropriate.
49 > - if 'h' in opts:
50 > - _os_merge.lstat(path)
51 > - else:
52 > - _os_merge.stat(path)
53 > - # Make sure the binary exists.
54 > - if not portage.process.find_binary('chflags'):
55 > - raise portage.exception.CommandNotFound('chflags')
56 > - # Now we're not sure exactly why it failed or what
57 > - # the real errno was, so just report EPERM.
58 > - output = _unicode_decode(output, encoding=encoding)
59 > - e = OSError(errno.EPERM, output)
60 > - e.errno = errno.EPERM
61 > - e.filename = path
62 > - e.message = output
63 > - raise e
64 > -
65 > - @classmethod
66 > - def lchflags(cls, path, flags):
67 > - return cls.chflags(path, flags, opts='-h')
68 > + chflags = os.chflags
69 > + lchflags = os.lchflags
70 >
71 > def load_mod(name):
72 > modname = ".".join(name.split(".")[:-1])
73 >
74
75 Looks good, thanks!
76 --
77 Thanks,
78 Zac

Attachments

File name MIME type
signature.asc application/pgp-signature