Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B #3244: Prevent race condition in ln.ssh #3935

Merged
merged 1 commit into from
Nov 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/tm_mad/qcow2/ln.ssh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ DST_SNAP_DIR=${DST_PATH}.snap
DST_FILE=`basename $DST_PATH`
DST_DIR=`dirname $DST_PATH`

SRC_HOST=`arg_host $SRC`
SRC_PATH=`arg_path $SRC`
SRC_SNAP_DIR=${SRC_PATH}.snap

Expand All @@ -64,21 +63,26 @@ ssh_make_path $DST_HOST $DST_DIR 'ssh'
#-------------------------------------------------------------------------------
log "Copying $SRC_PATH in $DST"

CMD=$(cat <<EOT
set -ex -o pipefail
mkdir -p "${DST_SNAP_DIR}"
cd "${DST_SNAP_DIR}"

if [ -d ${SRC_SNAP_DIR} ]; then
if [ -d "${SRC_SNAP_DIR}" ]; then
CP_CMD=$(cat <<EOT
for F in \$(ls ${SRC_SNAP_DIR}); do
if [ -f ${SRC_SNAP_DIR}/\$F ]; then
cp ${SRC_SNAP_DIR}/\$F .
cp ${SRC_SNAP_DIR}/\$F ${DST_SNAP_DIR}
fi
done
EOT
)
else
cp ${SRC_PATH} 0
CP_CMD="cp ${SRC_PATH} ${DST_SNAP_DIR}/0"
fi

CMD=$(cat <<EOT
set -ex -o pipefail
mkdir -p "${DST_SNAP_DIR}"
cd "${DST_SNAP_DIR}"

${CP_CMD}

rm -f "${DST_FILE}.snap"
ln -sf "." "${DST_FILE}.snap"

Expand Down