Skip to content

Commit 8ccc999

Browse files
sawenzelshahor02
authored andcommitted
Fix a quoting problem related to CCDB remapping
The CCDB remapping arguments appeared sometimes correctly quoted and in some cases not. This is because the task_finalizer reapplied string construction/quoting which was not generic enough. This is fixed with this commit. In addition, we now automatically quote ALIEN_JDL_REMAPPING if needed. Both versions ``` export ALIEN_JDL_REMAPPING="foo;bar" ``` as well as (quoted) ``` export ALIEN_JDL_REMAPPING='"foo;bar"' ``` will work. It is recommended to just use the former.
1 parent aef777f commit 8ccc999

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

MC/bin/o2dpg_dpl_config_tools.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,23 @@ def log_line(logger, message):
161161
else:
162162
logger.write(message + "\n")
163163

164+
def quote_for_nested_string(val):
165+
s = str(val)
166+
# Already double-quoted?
167+
if s.startswith('"') and s.endswith('"'):
168+
return s
169+
# Escape inner quotes
170+
s_escaped = s.replace('"', r'\"')
171+
return f'"{s_escaped}"'
172+
173+
def quote_if_needed(val):
174+
# Only quote values that are likely to break shell parsing
175+
# or contain nested shell-sensitive characters
176+
s = str(val)
177+
if re.search(r'[ \t;:&|<>]', s):
178+
return quote_for_nested_string(s)
179+
return s
180+
164181
def modify_dpl_command(cmd_str, config_anchor, allow_overwrite=False, logger=None, configname=None):
165182
# check if cmd_str is given as list, in which case we transfrom to string
166183
if isinstance(cmd_str, list) == True:
@@ -196,12 +213,6 @@ def modify_dpl_command(cmd_str, config_anchor, allow_overwrite=False, logger=Non
196213
added = []
197214
overwritten = []
198215

199-
def quote_if_needed(val):
200-
s = str(val)
201-
if " " in s and not (s.startswith('"') and s.endswith('"')):
202-
return f'"{s}"'
203-
return s
204-
205216
# Step 1: Existing options (preserved or overwritten)
206217
for key, val in existing_opts.items():
207218
if allow_overwrite and key in anchor_opts:

MC/bin/o2dpg_sim_workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from o2dpg_workflow_utils import createTask, createGlobalInitTask, dump_workflow, adjust_RECO_environment, isActive, activate_detector, deactivate_detector, compute_n_workers, merge_dicts
4444
from o2dpg_qc_finalization_workflow import include_all_QC_finalization
4545
from o2dpg_sim_config import create_sim_config, create_geant_config, constructConfigKeyArg, option_if_available, overwrite_config
46-
from o2dpg_dpl_config_tools import parse_command_string, modify_dpl_command, dpl_option_from_config, TaskFinalizer
46+
from o2dpg_dpl_config_tools import dpl_option_from_config, TaskFinalizer, quote_if_needed
4747

4848
# for some JAliEn interaction
4949
from alienpy.alien import JAlien
@@ -504,7 +504,7 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True):
504504
if ccdbbackend:
505505
common=common + " --condition-not-after " + str(args.condition_not_after)
506506
if ccdbRemap != None:
507-
common=common + " --condition-remap " + ccdbRemap
507+
common=common + f" --condition-remap {quote_if_needed(ccdbRemap)} "
508508
if args.noIPC!=None:
509509
return common + " --no-IPC "
510510
if bigshm:

0 commit comments

Comments
 (0)