mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Micro-optimization: replace s.find(x)!=-1 with x in s
timeit shows a speedup of ~3x on Python 2.7.5 x86_64. It also makes the code a bit shorter.
This commit is contained in:
committed by
Michael DeHaan
parent
a7da5d8702
commit
0749112286
@@ -415,7 +415,7 @@ class Runner(object):
|
||||
|
||||
environment_string = self._compute_environment_string(inject)
|
||||
|
||||
if tmp.find("tmp") != -1 and ((self.sudo and self.sudo_user != 'root') or (self.su and self.su_user != 'root')):
|
||||
if "tmp" in tmp and ((self.sudo and self.sudo_user != 'root') or (self.su and self.su_user != 'root')):
|
||||
# deal with possible umask issues once sudo'ed to other user
|
||||
cmd_chmod = "chmod a+r %s" % remote_module_path
|
||||
self._low_level_exec_command(conn, cmd_chmod, tmp, sudoable=False)
|
||||
@@ -469,7 +469,7 @@ class Runner(object):
|
||||
cmd = " ".join([environment_string.strip(), shebang.replace("#!","").strip(), cmd])
|
||||
cmd = cmd.strip()
|
||||
|
||||
if tmp.find("tmp") != -1 and not C.DEFAULT_KEEP_REMOTE_FILES and not persist_files and delete_remote_tmp:
|
||||
if "tmp" in tmp and not C.DEFAULT_KEEP_REMOTE_FILES and not persist_files and delete_remote_tmp:
|
||||
if not self.sudo or self.su or self.sudo_user == 'root' or self.su_user == 'root':
|
||||
# not sudoing or sudoing to root, so can cleanup files in the same step
|
||||
cmd = cmd + "; rm -rf %s >/dev/null 2>&1" % tmp
|
||||
@@ -485,7 +485,7 @@ class Runner(object):
|
||||
else:
|
||||
res = self._low_level_exec_command(conn, cmd, tmp, sudoable=sudoable, in_data=in_data)
|
||||
|
||||
if tmp.find("tmp") != -1 and not C.DEFAULT_KEEP_REMOTE_FILES and not persist_files and delete_remote_tmp:
|
||||
if "tmp" in tmp and not C.DEFAULT_KEEP_REMOTE_FILES and not persist_files and delete_remote_tmp:
|
||||
if (self.sudo and self.sudo_user != 'root') or (self.su and self.su_user != 'root'):
|
||||
# not sudoing to root, so maybe can't delete files as that other user
|
||||
# have to clean up temp files as original user in a second step
|
||||
@@ -883,7 +883,7 @@ class Runner(object):
|
||||
return False
|
||||
|
||||
def _late_needs_tmp_path(self, conn, tmp, module_style):
|
||||
if tmp.find("tmp") != -1:
|
||||
if "tmp" in tmp:
|
||||
# tmp has already been created
|
||||
return False
|
||||
if not conn.has_pipelining or not C.ANSIBLE_SSH_PIPELINING or C.DEFAULT_KEEP_REMOTE_FILES or self.su:
|
||||
|
||||
Reference in New Issue
Block a user