From 0e1be34687beccc0bdbccfac6a83006e040d54b7 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Tue, 20 Oct 2020 17:11:34 +0200 Subject: lib/common-functions: failsafe_sftp(): use less magic for $master_mirror_sftp_root - simply cd $master_mirror_sftp_root before doing anything else --- lib/common-functions | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/common-functions b/lib/common-functions index b64af00..8b842ff 100755 --- a/lib/common-functions +++ b/lib/common-functions @@ -871,12 +871,6 @@ failsafe_sftp() { trial_counter=20 trap 'rm -rf --one-file-system "${temp_dir}"' EXIT cat > "${temp_dir}/input" - if [ -n "${master_mirror_sftp_root}" ]; then - sed -i ' - /^\(rm\|rename\) / s@"\([^"]\+\)"@"'"${master_mirror_sftp_root}"'/\1"@g - /^ln / s@"\([^"]\+\)"$@"'"${master_mirror_sftp_root}"'/\1"@ - ' "${temp_dir}/input" - fi sed -n ' s/^rm "\([^"]\+\)"$/- \1/ s/^ln\( [^"]\S*\)* "[^"]\+" "\([^"]\+\)"$/+ \2/ @@ -885,7 +879,10 @@ failsafe_sftp() { p ' "${temp_dir}/input" > \ "${temp_dir}/expectations" - if ${master_mirror_sftp_command} < "${temp_dir}/input"; then + if sed ' + 1 i cd "'"${master_mirror_sftp_root}"'" + ' "${temp_dir}/input" \ + | ${master_mirror_sftp_command}; then # we're done exit 0 fi @@ -901,13 +898,18 @@ failsafe_sftp() { # - succeeding sftp command to create listing (e.g. all expected # files are found) # - no unexpected files were found - if ${master_mirror_sftp_command} < \ - "${temp_dir}/input" && \ + if sed ' + 1 i cd "'"${master_mirror_sftp_root}"'" + ' "${temp_dir}/input" \ + | ${master_mirror_sftp_command} && \ sed ' s/^+ \(\S\+\)$/ls -1 "\1"/ s,^- \(\S\+/\)[^/]\+$,ls -1 "\1", ' "${temp_dir}/expectations" | \ sort -u | \ + sed ' + 1 i cd "'"${master_mirror_sftp_root}"'" + ' "${temp_dir}/input" | \ ${master_mirror_sftp_command} > "${temp_dir}/check" && \ ! grep -qxF "$( sed -n ' -- cgit v1.2.3-70-g09d2