Improved escaping of file names

This commit is contained in:
Louwrentius 2009-03-27 21:54:15 +00:00
parent fcaffcd6ac
commit 407e41dac3
1 changed files with 25 additions and 21 deletions

View File

@ -83,6 +83,7 @@ TRANSFER_TO_SLAVE="0" # Transfer item to slave via (s)cp.
SECURE_COPY="1" # If set, use SCP, Otherwise, use cp. SECURE_COPY="1" # If set, use SCP, Otherwise, use cp.
REMOTE_OUTPUT_DIR="" # Remote directory to which output must be uploaded. REMOTE_OUTPUT_DIR="" # Remote directory to which output must be uploaded.
SCRIPT="" # Custom user script that is executed by ppss. SCRIPT="" # Custom user script that is executed by ppss.
ITEM_ESCAPED=""
showusage () { showusage () {
@ -716,8 +717,8 @@ deploy_ppss () {
else else
for NODE in `cat $NODES_FILE` for NODE in `cat $NODES_FILE`
do do
deploy "$NODE" & deploy "$NODE"
sleep 0.5 sleep 0.1
done done
fi fi
} }
@ -900,6 +901,19 @@ are_jobs_running () {
fi fi
} }
escape_item () {
TMP="$1"
ITEM_ESCAPED=`echo "$TMP" | \
sed s/\\ /\\\\\\\\\\\\\\ /g | \
sed s/\\'/\\\\\\\\\\\\\\'/g | \
sed s/\&/\\\\\\\\\\\\\\&/g | \
sed s/\;/\\\\\\\\\\\\\\;/g | \
sed s/\(/\\\\\\\\\\(/g | \
sed s/\)/\\\\\\\\\\)/g `
}
download_item () { download_item () {
ITEM="$1" ITEM="$1"
@ -916,12 +930,9 @@ download_item () {
else else
ITEM_PATH="$ITEM" ITEM_PATH="$ITEM"
fi fi
ITEM_ESCAPED=`echo "$ITEM_PATH" | \
sed s/\\ /\\\\\\\\\\\\\\ /g | \ escape_item "$ITEM_PATH"
sed s/\\'/\\\\\\\\\\\\\\'/g | \
sed s/\&/\\\\\\\\\\\\\\&/g | \
sed s/\(/\\\\\\\\\\(/g | \
sed s/\)/\\\\\\\\\\)/g `
scp -q $SSH_OPTS $SSH_KEY $USER@$SSH_SERVER:"$ITEM_ESCAPED" ./$PPSS_LOCAL_TMPDIR scp -q $SSH_OPTS $SSH_KEY $USER@$SSH_SERVER:"$ITEM_ESCAPED" ./$PPSS_LOCAL_TMPDIR
log DEBUG "Exit code of remote transfer is $?" log DEBUG "Exit code of remote transfer is $?"
else else
@ -948,12 +959,8 @@ upload_item () {
log DEBUG "Uploading item $ITEM." log DEBUG "Uploading item $ITEM."
if [ "$SECURE_COPY" == "1" ] if [ "$SECURE_COPY" == "1" ]
then then
DIR_ESCAPED=`echo "$REMOTE_OUTPUT_DIR$ITEMDIR" | \ escape_item "$REMOTE_OUTPUT_DIR$ITEMDIR"
sed s/\\ /\\\\\\\\\\\\\\ /g | \ DIR_ESCAPED="$ITEM_ESCAPED"
sed s/\\'/\\\\\\\\\\\\\\'/g | \
sed s/\&/\\\\\\\\\\\\\\&/g | \
sed s/\(/\\\\\\\\\\(/g | \
sed s/\)/\\\\\\\\\\)/g `
scp -q $SSH_OPTS $SSH_KEY "$ITEM"/* $USER@$SSH_SERVER:"$DIR_ESCAPED" scp -q $SSH_OPTS $SSH_KEY "$ITEM"/* $USER@$SSH_SERVER:"$DIR_ESCAPED"
ERROR="$?" ERROR="$?"
@ -965,7 +972,7 @@ upload_item () {
rm -rf ./"$ITEM" rm -rf ./"$ITEM"
fi fi
else else
cp "$ITEM" $REMOTE_OUTPUT_DIR cp "$ITEM" "$REMOTE_OUTPUT_DIR"
ERROR="$?" ERROR="$?"
if [ ! "$ERROR" == "0" ] if [ ! "$ERROR" == "0" ]
then then
@ -988,6 +995,7 @@ lock_item () {
sed s/\\ /\\\\\\\\\\\\\\ /g | \ sed s/\\ /\\\\\\\\\\\\\\ /g | \
sed s/\\'/\\\\\\\\\\\\\\'/g | \ sed s/\\'/\\\\\\\\\\\\\\'/g | \
sed s/\&/\\\\\\\\\\\\\\&/g | \ sed s/\&/\\\\\\\\\\\\\\&/g | \
sed s/\;/\\\\\\\\\\\\\\;/g | \
sed s/\(/\\\\\\\\\\(/g | \ sed s/\(/\\\\\\\\\\(/g | \
sed s/\)/\\\\\\\\\\)/g ` sed s/\)/\\\\\\\\\\)/g `
@ -1229,12 +1237,8 @@ commando () {
fi fi
NEWDIR="$REMOTE_OUTPUT_DIR/$DIRNAME" NEWDIR="$REMOTE_OUTPUT_DIR/$DIRNAME"
DIR_ESCAPED=`echo "$NEWDIR" | \ escape_item "$NEWDIR"
sed s/\\ /\\\\\\\\\\\\\\ /g | \ DIR_ESCAPED="$ITEM_ESCAPED"
sed s/\\'/\\\\\\\\\\\\\\'/g | \
sed s/\&/\\\\\\\\\\\\\\&/g | \
sed s/\(/\\\\\\\\\\(/g | \
sed s/\)/\\\\\\\\\\)/g `
exec_cmd "mkdir -p $DIR_ESCAPED" exec_cmd "mkdir -p $DIR_ESCAPED"
if [ "$DIRNAME" == "." ] if [ "$DIRNAME" == "." ]