* [gentoo-portage-dev] [PATCH] FreeBSD: use os.*chflags() instead of calling external tool
@ 2018-02-22 15:18 99% Michał Górny
0 siblings, 0 replies; 1+ results
From: Michał Górny @ 2018-02-22 15:18 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Michał Górny
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 < 0x3020000 and sys.hexversion >= 0x3000000:
- # 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])
--
2.16.2
^ permalink raw reply related [relevance 99%]
Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2018-02-22 15:18 99% [gentoo-portage-dev] [PATCH] FreeBSD: use os.*chflags() instead of calling external tool Michał Górny
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox