Skip to content

Commit 9dfbb8e

Browse files
authored
fix(install_config): replace cp -nv with explicit file existence check (#4897)
* fix(install_config): replace cp -nv with explicit file existence check Newer coreutils (Ubuntu 24.04+, Debian 13+) emit a portability warning when using cp -n: 'behavior of -n is non-portable and may change in future'. Replace all cp -nv usages with an explicit [ ! -f dest ] guard, which is portable across all distros and preserves the same OK/SKIP/FAIL behaviour. * fix(install_config): use -e and -L checks to handle broken symlinks Using only -f missed broken symlinks (-e returns false for them but -L returns true). Use both checks to match the skip behaviour of cp -n.
1 parent cba689a commit 9dfbb8e

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

lgsm/modules/install_config.sh

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ fn_default_config_remote() {
3434
if [ "${config}" == "${servercfgdefault}" ]; then
3535
mkdir -p "${servercfgdir}"
3636
echo -en "copying config file [ ${italic}${servercfgfullpath}${default} ]"
37-
changes+=$(cp -nv "${lgsmdir}/config-default/config-game/${config}" "${servercfgfullpath}")
38-
exitcode=$?
37+
if [ ! -e "${servercfgfullpath}" ] && [ ! -L "${servercfgfullpath}" ]; then
38+
cp "${lgsmdir}/config-default/config-game/${config}" "${servercfgfullpath}"
39+
exitcode=$?
40+
[ "${exitcode}" -eq 0 ] && changes="copied"
41+
else
42+
exitcode=0
43+
fi
3944
if [ "${exitcode}" -ne 0 ]; then
4045
fn_print_fail_eol_nl
4146
fn_script_log_fail "copying config file ${servercfgfullpath}"
@@ -48,7 +53,13 @@ fn_default_config_remote() {
4853
elif [ "${shortname}" == "arma3" ] && [ "${config}" == "${networkcfgdefault}" ]; then
4954
mkdir -p "${servercfgdir}"
5055
echo -en "copying config file [ ${italic}${networkcfgfullpath}${default} ]"
51-
changes+=$(cp -nv "${lgsmdir}/config-default/config-game/${config}" "${networkcfgfullpath}")
56+
if [ ! -e "${networkcfgfullpath}" ] && [ ! -L "${networkcfgfullpath}" ]; then
57+
cp "${lgsmdir}/config-default/config-game/${config}" "${networkcfgfullpath}"
58+
exitcode=$?
59+
[ "${exitcode}" -eq 0 ] && changes="copied"
60+
else
61+
exitcode=0
62+
fi
5263
if [ "${exitcode}" -ne 0 ]; then
5364
fn_print_fail_eol_nl
5465
fn_script_log_fail "copying config file ${networkcfgdefault}"
@@ -60,7 +71,13 @@ fn_default_config_remote() {
6071
fi
6172
elif [ "${shortname}" == "dst" ] && [ "${config}" == "${clustercfgdefault}" ]; then
6273
echo -en "copying config file [ ${italic}${clustercfgfullpath}${default} ]"
63-
changes+=$(cp -nv "${lgsmdir}/config-default/config-game/${clustercfgdefault}" "${clustercfgfullpath}")
74+
if [ ! -e "${clustercfgfullpath}" ] && [ ! -L "${clustercfgfullpath}" ]; then
75+
cp "${lgsmdir}/config-default/config-game/${clustercfgdefault}" "${clustercfgfullpath}"
76+
exitcode=$?
77+
[ "${exitcode}" -eq 0 ] && changes="copied"
78+
else
79+
exitcode=0
80+
fi
6481
if [ "${exitcode}" -ne 0 ]; then
6582
fn_print_fail_eol_nl
6683
fn_script_log_fail "copying config file ${clustercfgfullpath}"
@@ -72,7 +89,13 @@ fn_default_config_remote() {
7289
fi
7390
else
7491
echo -en "copying config file [ ${italic}${servercfgdir}/${config}${default} ]"
75-
changes+=$(cp -nv "${lgsmdir}/config-default/config-game/${config}" "${servercfgdir}/${config}")
92+
if [ ! -e "${servercfgdir}/${config}" ] && [ ! -L "${servercfgdir}/${config}" ]; then
93+
cp "${lgsmdir}/config-default/config-game/${config}" "${servercfgdir}/${config}"
94+
exitcode=$?
95+
[ "${exitcode}" -eq 0 ] && changes="copied"
96+
else
97+
exitcode=0
98+
fi
7699
if [ "${exitcode}" -ne 0 ]; then
77100
fn_print_fail_eol_nl
78101
fn_script_log_fail "copying config file ${servercfgdir}/${config}"

0 commit comments

Comments
 (0)