TT#40300 Use «readlink -f» for the destination file of the mv

We need to preserve symlinks, as was the case when we were using cat.

This way we'll not get caught in the ETXTBSY race from the kernel, and
we'll have the old semantics.

Bisected-by: Alex Lutay <alutay@sipwise.com>
Fixes: 7480ebe7c5
Change-Id: I0be7473b271cc3807da957bbef1063018d3b42b2
changes/50/22550/2
Guillem Jover 8 years ago
parent e218928a60
commit 8fc290600a

@ -83,8 +83,10 @@ tt_tmp_output_file="$(mktemp ngcpcfg."${tt_tmp_output_file_base}".XXXXXXXXXX)"
log_debug "Output file ${output_file} based on ${input_file}"
log_debug "Executing: $TT_WRAPPER ${input_file} > ${tt_tmp_output_file}"
log_debug " and: mv ${tt_tmp_output_file} ${output_file}"
# We need to use «readlink -f» so that we do not destroy any symlink pointing
# to the real file, which we were previously preserving while using «cat».
if "$TT_WRAPPER" "${input_file}" > "${tt_tmp_output_file}" 2>/dev/null &&
mv "${tt_tmp_output_file}" "${output_file}" ; then
mv "${tt_tmp_output_file}" "$(readlink -f "${output_file}")" ; then
log_info "Generating ${output_file}: OK"
RC=0
else

Loading…
Cancel
Save