Gentoo Archives: gentoo-portage-dev

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

Replies