[stable-2.11] subversion - fix stack trace when getting repository information (#74405) (#74977)

* subversion - set LC_ALL for accurate command output parsing

When LC_ALL is not set, the output language of commands will differ based on locale. There
is a lot of history of trying to fix this. See the following pull requests:

https://github.com/ansible/ansible-modules-core/pull/4358
https://github.com/ansible/ansible-modules-core/pull/4358

This patch attempts to fix this my setting LC_ALL to a UTF-8 locale. Setting LC_ALL to C reintroduces this bug https://github.com/ansible/ansible-modules-core/issues/4178.

I'm sure there are some problems I am not seeing with setting this to en_US.UTF-8, but that is
the only way I could find to fix this bug without reintriducing the bug mentioned above.

* Rather than setting locale, just check for matches before trying to get groups

This is a pragmatic solution to avoid the stack trace since setting the locale correctly
to ensure message parsing is accurate is problematic.

* Improve regexps for finding revision and URL
(cherry picked from commit a8cf0196f7)

Co-authored-by: Sam Doran <sdoran@redhat.com>
pull/75001/head
Sam Doran 3 years ago committed by GitHub
parent f92f039ea7
commit fad56bd4e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- subversion - fix stack trace when getting information about the repository (https://github.com/ansible/ansible/issues/36498)

@ -134,6 +134,13 @@ from ansible.module_utils.basic import AnsibleModule
class Subversion(object):
# Example text matched by the regexp:
# Révision : 1889134
# 版本: 1889134
# Revision: 1889134
REVISION_RE = r'^\w+\s?:\s+\d+$'
def __init__(self, module, dest, repo, revision, username, password, svn_path, validate_certs):
self.module = module
self.dest = dest
@ -228,14 +235,28 @@ class Subversion(object):
def get_revision(self):
'''Revision and URL of subversion working directory.'''
text = '\n'.join(self._exec(["info", self.dest]))
rev = re.search(r'^Revision:.*$', text, re.MULTILINE).group(0)
url = re.search(r'^URL:.*$', text, re.MULTILINE).group(0)
rev = re.search(self.REVISION_RE, text, re.MULTILINE)
if rev:
rev = rev.group(0)
else:
rev = 'Unable to get revision'
url = re.search(r'^URL\s?:.*$', text, re.MULTILINE)
if url:
url = url.group(0)
else:
url = 'Unable to get URL'
return rev, url
def get_remote_revision(self):
'''Revision and URL of subversion working directory.'''
text = '\n'.join(self._exec(["info", self.repo]))
rev = re.search(r'^Revision:.*$', text, re.MULTILINE).group(0)
rev = re.search(self.REVISION_RE, text, re.MULTILINE)
if rev:
rev = rev.group(0)
else:
rev = 'Unable to get remote revision'
return rev
def has_local_mods(self):
@ -250,7 +271,11 @@ class Subversion(object):
def needs_update(self):
curr, url = self.get_revision()
out2 = '\n'.join(self._exec(["info", "-r", self.revision, self.dest]))
head = re.search(r'^Revision:.*$', out2, re.MULTILINE).group(0)
head = re.search(self.REVISION_RE, out2, re.MULTILINE)
if head:
head = head.group(0)
else:
head = 'Unable to get revision'
rev1 = int(curr.split(':')[1].strip())
rev2 = int(head.split(':')[1].strip())
change = False

Loading…
Cancel
Save