Use same concatenation method between functions to avoid future confusion

I didn't notice that db_dump and db_import were different, thus I introduced a bug with the initialization of the variable cmd. This commit fixes that.
This commit is contained in:
Laurent Indermuehle 2025-03-06 17:47:15 +01:00
parent 498356c14e
commit cae24548c7
No known key found for this signature in database
GPG key ID: 93FA944C9F34DD09

View file

@ -398,63 +398,63 @@ def db_dump(module, host, user, password, db_name, target, all_databases, port,
# If defined, mysqldump demands --defaults-extra-file be the first option
if config_file:
if restrict_config_file:
cmd += " --defaults-file=%s" % shlex_quote(config_file)
cmd.append("--defaults-file=%s" % shlex_quote(config_file))
else:
cmd += " --defaults-extra-file=%s" % shlex_quote(config_file)
cmd.append("--defaults-extra-file=%s" % shlex_quote(config_file))
if check_implicit_admin:
cmd += " --user=root --password=''"
cmd.append("--user=root --password=''")
else:
if user is not None:
cmd += " --user=%s" % shlex_quote(user)
cmd.append("--user=%s" % shlex_quote(user))
if password is not None:
if not unsafe_password:
cmd += " --password=%s" % shlex_quote(password)
cmd.append("--password=%s" % shlex_quote(password))
else:
cmd += " --password=%s" % password
cmd.append("--password=%s" % password)
if ssl_cert is not None:
cmd += " --ssl-cert=%s" % shlex_quote(ssl_cert)
cmd.append("--ssl-cert=%s" % shlex_quote(ssl_cert))
if ssl_key is not None:
cmd += " --ssl-key=%s" % shlex_quote(ssl_key)
cmd.append("--ssl-key=%s" % shlex_quote(ssl_key))
if ssl_ca is not None:
cmd += " --ssl-ca=%s" % shlex_quote(ssl_ca)
cmd.append("--ssl-ca=%s" % shlex_quote(ssl_ca))
if force:
cmd += " --force"
cmd.append("--force")
if socket is not None:
cmd += " --socket=%s" % shlex_quote(socket)
cmd.append("--socket=%s" % shlex_quote(socket))
else:
cmd += " --host=%s --port=%i" % (shlex_quote(host), port)
cmd.append("--host=%s --port=%i" % (shlex_quote(host), port))
if all_databases:
cmd += " --all-databases"
cmd.append("--all-databases")
elif len(db_name) > 1:
cmd += " --databases {0}".format(' '.join(db_name))
cmd.append("--databases {0}".format(' '.join(db_name)))
else:
cmd += " %s" % shlex_quote(' '.join(db_name))
cmd.append("%s" % shlex_quote(' '.join(db_name)))
if skip_lock_tables:
cmd += " --skip-lock-tables"
cmd.append("--skip-lock-tables")
if (encoding is not None) and (encoding != ""):
cmd += " --default-character-set=%s" % shlex_quote(encoding)
cmd.append("--default-character-set=%s" % shlex_quote(encoding))
if single_transaction:
cmd += " --single-transaction=true"
cmd.append("--single-transaction=true")
if quick:
cmd += " --quick"
cmd.append("--quick")
if ignore_tables:
for an_ignored_table in ignore_tables:
cmd += " --ignore-table={0}".format(an_ignored_table)
cmd.append("--ignore-table={0}".format(an_ignored_table))
if hex_blob:
cmd += " --hex-blob"
cmd.append("--hex-blob")
if master_data:
if (server_implementation == 'mysql' and
LooseVersion(server_version) >= LooseVersion("8.2.0")):
cmd += " --source-data=%s" % master_data
cmd.append("--source-data=%s" % master_data)
else:
cmd += " --master-data=%s" % master_data
cmd.append("--master-data=%s" % master_data)
if dump_extra_args is not None:
cmd += " " + dump_extra_args
cmd.append(dump_extra_args)
path = None
if os.path.splitext(target)[-1] == '.gz':
@ -466,6 +466,8 @@ def db_dump(module, host, user, password, db_name, target, all_databases, port,
elif os.path.splitext(target)[-1] == '.zst':
path = module.get_bin_path('zstd', True)
cmd = ' '.join(cmd)
if path:
cmd = '%s | %s > %s' % (cmd, path, shlex_quote(target))
if pipefail: