diff options
author | Zac Medico <zmedico@gentoo.org> | 2010-09-07 15:01:22 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2010-09-07 15:01:22 -0700 |
commit | d2a44a248d75646ea282647087967ca51e9b1988 (patch) | |
tree | 38929c80c2300eb77beeff0ae92e7137f87e1b25 | |
parent | 790bc7470c3047a06b5b97a7a5b4e4eab0de7cad (diff) | |
download | portage-d2a44a248d75646ea282647087967ca51e9b1988.tar.gz portage-d2a44a248d75646ea282647087967ca51e9b1988.tar.bz2 portage-d2a44a248d75646ea282647087967ca51e9b1988.zip |
Bug #336349 - Make getconfig() warn about dos-style line endings in
config files, since that prevents people from being able to source
them with bash.
-rw-r--r-- | pym/portage/util/__init__.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py index fa8ba6f6a..b897f77f8 100644 --- a/pym/portage/util/__init__.py +++ b/pym/portage/util/__init__.py @@ -405,9 +405,6 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True): expand_map = {} mykeys = {} try: - # Workaround for avoiding a silent error in shlex that - # is triggered by a source statement at the end of the file without a - # trailing newline after the source statement # NOTE: shex doesn't seem to support unicode objects # (produces spurious \0 characters with python-2.6.2) if sys.hexversion < 0x3000000: @@ -417,8 +414,6 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True): content = open(_unicode_encode(mycfg, encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['content'], errors='replace').read() - if content and content[-1] != '\n': - content += '\n' except IOError as e: if e.errno == PermissionDenied.errno: raise PermissionDenied(mycfg) @@ -427,6 +422,19 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True): if e.errno not in (errno.EISDIR,): raise return None + + # Workaround for avoiding a silent error in shlex that is + # triggered by a source statement at the end of the file + # without a trailing newline after the source statement. + if content and content[-1] != '\n': + content += '\n' + + # Warn about dos-style line endings since that prevents + # people from being able to source them with bash. + if '\r' in content: + writemsg("!!! Please use dos2unix to convert line endings " + \ + "in config file: '%s'\n" % mycfg, noiselevel=-1) + try: if tolerant: shlex_class = _tolerant_shlex |