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

Replies