#284 Fix copy command

This commit is contained in:
Filippo Squillace 2022-01-05 23:47:55 +01:00
parent e6bae0647c
commit 7d8c619ee0
2 changed files with 6 additions and 4 deletions

View file

@ -276,20 +276,22 @@ function copy_passwd_and_group(){
! getent_cmd passwd ${USER} >> ${JUNEST_HOME}/etc/passwd
then
warn "getent command failed or does not exist. Binding directly from /etc/passwd."
copy_file /etc/passwd ${JUNEST_HOME}/etc/passwd
copy_file /etc/passwd
fi
if ! getent_cmd group > ${JUNEST_HOME}/etc/group
then
warn "getent command failed or does not exist. Binding directly from /etc/group."
copy_file /etc/group ${JUNEST_HOME}/etc/group
copy_file /etc/group
fi
return 0
}
function copy_file() {
local file="${1}"
[[ -r "$file" ]] && cp_cmd "$file" "${JUNEST_HOME}/$file"
# -f option ensure to remove destination file if it cannot be opened
# https://github.com/fsquillace/junest/issues/284
[[ -r "$file" ]] && cp_cmd -f "$file" "${JUNEST_HOME}/$file"
return 0
}

View file

@ -197,7 +197,7 @@ function test_copy_passwd_and_group_fallback(){
echo $@
}
CP=cp_cmd_mock GETENT=false LD_EXEC=false assertCommandSuccess copy_passwd_and_group
assertEquals "$(echo -e "/etc/passwd $JUNEST_HOME//etc/passwd\n/etc/group $JUNEST_HOME//etc/group")" "$(cat $STDOUTF)"
assertEquals "$(echo -e "-f /etc/passwd $JUNEST_HOME//etc/passwd\n-f /etc/group $JUNEST_HOME//etc/group")" "$(cat $STDOUTF)"
}
function test_copy_passwd_and_group_failure(){