On 02/22/2018 07:18 AM, Michał Górny wrote:
> Use os.chflags() and os.lchflags() built-in functions instead of calling
> external 'chflags' tool on FreeBSD. This fixes major performance
> problems Portage has on FreeBSD.
>
> Bug: https://bugs.gentoo.org/648432
> ---
> pym/portage/__init__.py | 52
> +++--
> 1 file changed, 7 insertions(+), 45 deletions(-)
>
> diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
> index 0e036b12e..4f43a2c32 100644
> --- a/pym/portage/__init__.py
> +++ b/pym/portage/__init__.py
> @@ -422,51 +422,13 @@ if platform.system() in ('FreeBSD',):
>
> class bsd_chflags(object):
>
> - @classmethod
> - def chflags(cls, path, flags, opts=""):
> - cmd = ['chflags']
> - if opts:
> - cmd.append(opts)
> - cmd.append('%o' % (flags,))
> - cmd.append(path)
> -
> - if sys.hexversion < 0x302 and sys.hexversion >=
> 0x300:
> - # Python 3.1 _execvp throws TypeError for
> non-absolute executable
> - # path passed as bytes (see
> https://bugs.python.org/issue8513).
> - fullname = process.find_binary(cmd[0])
> - if fullname is None:
> - raise exception.CommandNotFound(cmd[0])
> - cmd[0] = fullname
> -
> - encoding = _encodings['fs']
> - cmd = [_unicode_encode(x, encoding=encoding,
> errors='strict')
> - for x in cmd]
> - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
> - stderr=subprocess.STDOUT)
> - output = proc.communicate()[0]
> - status = proc.wait()
> - if os.WIFEXITED(status) and os.WEXITSTATUS(status) ==
> os.EX_OK:
> - return
> - # Try to generate an ENOENT error if appropriate.
> - if 'h' in opts:
> - _os_merge.lstat(path)
> - else:
> - _os_merge.stat(path)
> - # Make sure the binary exists.
> - if not portage.process.find_binary('chflags'):
> - raise
> portage.exception.CommandNotFound('chflags')
> - # Now we're not sure exactly why it failed or what
> - # the real errno was, so just report EPERM.
> - output = _unicode_decode(output, encoding=encoding)
> - e = OSError(errno.EPERM, output)
> - e.errno = errno.EPERM
> - e.filename = path
> - e.message = output
> - raise e
> -
> - @classmethod
> - def lchflags(cls, path, flags):
> - return cls.chflags(path, flags, opts='-h')
> + @staticmethod
> + def chflags(path, flags):
> + return os.chflags(path, flags)
> +
> + @staticmethod
> + def lchflags(path, flags):
> + return os.lchflags(path, flags)
>
> def load_mod(name):
> modname = ".".join(name.split(".")[:-1])
>
Looks good, please merge.
--
Thanks,
Zac
signature.asc
Description: OpenPGP digital signature