Gentoo Archives: gentoo-commits

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