From d69cca46d0e8a10410806baa7ccc60a7b7c416c5 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 27 Nov 2017 10:04:23 -0500 Subject: [PATCH] Rework check_globbing to reduce false positives First, globbing can only be the cause of a mess up if the given noderange is a file that matches. With this we still have: for node in $(nodelist compute); do nodepower $node; done As a potential false positive if any node is a range. For this, offer suggestion of changing directories. Also, if it had been: for NODE in $(nodelist compute); do export NODE; nodepower $NODE; done Another clause can detect that, which has been added. --- confluent_client/confluent/client.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/confluent_client/confluent/client.py b/confluent_client/confluent/client.py index d3bfb66d..7f7c3670 100644 --- a/confluent_client/confluent/client.py +++ b/confluent_client/confluent/client.py @@ -469,15 +469,24 @@ def updateattrib(session, updateargs, nodetype, noderange, options): # if we glob to something, then bash will change noderange and this should # detect it and save the user from tragedy def check_globbing(noderange): + if not os.path.exists(noderange): + return True rawargs = os.environ.get('CURRENT_CMDLINE', None) if rawargs: rawargs = shlex.split(rawargs) for arg in rawargs: + if arg.startswith('$'): + arg = arg[1:] + if arg.endswith(';'): + arg = arg[:-1] + arg = os.environ.get(arg, '$' + arg) if arg.startswith(noderange): break else: sys.stderr.write( - 'Shell glob conflict detected, specified target {0} ' - 'not in command line (if bash, try set -f)' + 'Shell glob conflict detected, specified target "{0}" ' + 'not in command line, but is a file. You can use "set -f" in ' + 'bash or change directories such that there is no filename ' + 'that would conflict.' '\n'.format(noderange)) sys.exit(1) \ No newline at end of file