Skip to content

Commit

Permalink
B #3244: Prevent race condition in ln.ssh (#3935)
Browse files Browse the repository at this point in the history
Don't evaluate presence of the SRC_SNAP_DIR on hypervisor,
but rather on the frontend to prevent race condition.
  • Loading branch information
xorel authored and Ruben S. Montero committed Nov 12, 2019
1 parent d4495e5 commit d625851
Showing 1 changed file with 13 additions and 9 deletions.
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

0 comments on commit d625851

Please sign in to comment.