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

Attachments

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