Pass svn arguments as a list of strings instead of using string substition to ensure all parameters are escaped properly.

pull/6201/head
Chris Church 11 years ago
parent ccb64e6358
commit 5c2c29e71f

@ -94,47 +94,46 @@ class Subversion(object):
def _exec(self, args): def _exec(self, args):
bits = [ bits = [
'LANG=C',
self.svn_path, self.svn_path,
'--non-interactive', '--non-interactive',
'--trust-server-cert', '--trust-server-cert',
'--no-auth-cache', '--no-auth-cache',
] ]
if self.username: if self.username:
bits.append("--username '%s'" % self.username) bits.extend(["--username", self.username])
if self.password: if self.password:
bits.append("--password '%s'" % self.password) bits.extend(["--password", self.password])
bits.append(args) bits.extend(args)
rc, out, err = self.module.run_command(' '.join(bits), check_rc=True) rc, out, err = self.module.run_command(bits, check_rc=True)
return out.splitlines() return out.splitlines()
def checkout(self): def checkout(self):
'''Creates new svn working directory if it does not already exist.''' '''Creates new svn working directory if it does not already exist.'''
self._exec("checkout -r %s '%s' '%s'" % (self.revision, self.repo, self.dest)) self._exec(["checkout", "-r", self.revision, self.repo, self.dest])
def switch(self): def switch(self):
'''Change working directory's repo.''' '''Change working directory's repo.'''
# switch to ensure we are pointing at correct repo. # switch to ensure we are pointing at correct repo.
self._exec("switch '%s' '%s'" % (self.repo, self.dest)) self._exec(["switch", self.repo, self.dest])
def update(self): def update(self):
'''Update existing svn working directory.''' '''Update existing svn working directory.'''
self._exec("update -r %s '%s'" % (self.revision, self.dest)) self._exec(["update", "-r", self.revision, self.dest])
def revert(self): def revert(self):
'''Revert svn working directory.''' '''Revert svn working directory.'''
self._exec("revert -R '%s'" % self.dest) self._exec(["revert", "-R", self.dest])
def get_revision(self): def get_revision(self):
'''Revision and URL of subversion working directory.''' '''Revision and URL of subversion working directory.'''
text = '\n'.join(self._exec("info '%s'" % self.dest)) text = '\n'.join(self._exec(["info", self.dest]))
rev = re.search(r'^Revision:.*$', text, re.MULTILINE).group(0) rev = re.search(r'^Revision:.*$', text, re.MULTILINE).group(0)
url = re.search(r'^URL:.*$', text, re.MULTILINE).group(0) url = re.search(r'^URL:.*$', text, re.MULTILINE).group(0)
return rev, url return rev, url
def has_local_mods(self): def has_local_mods(self):
'''True if revisioned files have been added or modified. Unrevisioned files are ignored.''' '''True if revisioned files have been added or modified. Unrevisioned files are ignored.'''
lines = self._exec("status '%s'" % self.dest) lines = self._exec(["status", self.dest])
# Match only revisioned files, i.e. ignore status '?'. # Match only revisioned files, i.e. ignore status '?'.
regex = re.compile(r'^[^?]') regex = re.compile(r'^[^?]')
# Has local mods if more than 0 modifed revisioned files. # Has local mods if more than 0 modifed revisioned files.
@ -142,7 +141,7 @@ class Subversion(object):
def needs_update(self): def needs_update(self):
curr, url = self.get_revision() curr, url = self.get_revision()
out2 = '\n'.join(self._exec("info -r HEAD '%s'" % self.dest)) out2 = '\n'.join(self._exec(["info", "-r", "HEAD", self.dest]))
head = re.search(r'^Revision:.*$', out2, re.MULTILINE).group(0) head = re.search(r'^Revision:.*$', out2, re.MULTILINE).group(0)
rev1 = int(curr.split(':')[1].strip()) rev1 = int(curr.split(':')[1].strip())
rev2 = int(head.split(':')[1].strip()) rev2 = int(head.split(':')[1].strip())
@ -176,6 +175,7 @@ def main():
password = module.params['password'] password = module.params['password']
svn_path = module.params['executable'] or module.get_bin_path('svn', True) svn_path = module.params['executable'] or module.get_bin_path('svn', True)
os.environ['LANG'] = 'C'
svn = Subversion(module, dest, repo, revision, username, password, svn_path) svn = Subversion(module, dest, repo, revision, username, password, svn_path)
if not os.path.exists(dest): if not os.path.exists(dest):

Loading…
Cancel
Save