Handle torrent files with spaces in their name

This commit is contained in:
Tony Blyler 2015-03-01 00:00:26 -05:00
parent cd5263cb5e
commit 30b0258294

View file

@ -253,16 +253,15 @@ while true; do
echo "${TORRENT_FILE_PATH} Does not exist" echo "${TORRENT_FILE_PATH} Does not exist"
exit 1 exit 1
fi fi
OIFS="$IFS"
IFS=$'\n'
# enumerate the .torrent file directory # enumerate the .torrent file directory
for file in `ls "${TORRENT_FILE_PATH}"`; do for file in `find "${TORRENT_FILE_PATH}"`; do
# store the file/directory's full path
file="${TORRENT_FILE_PATH}/${file}"
# check if the path is a directory # check if the path is a directory
if [[ -d "${file}" ]]; then if [[ -d "${file}" ]]; then
# enumerate the directory # enumerate the directory
for sub_file in `ls "${file}"`; do for sub_file in `find "${file}" -type f`; do
# store the file/directory's full path
sub_file="${file}/${sub_file}"
# this is the furthest we will descend # this is the furthest we will descend
if [[ -f "${sub_file}" ]]; then if [[ -f "${sub_file}" ]]; then
# get the torrent hash for the .torrent file # get the torrent hash for the .torrent file
@ -293,6 +292,7 @@ while true; do
fi fi
fi fi
done done
IFS="$OIFS"
# go through the torrent queue # go through the torrent queue
for torrent_hash in "${!TORRENT_QUEUE[@]}"; do for torrent_hash in "${!TORRENT_QUEUE[@]}"; do
@ -317,9 +317,12 @@ while true; do
fi fi
done done
# if the amount of running rsyncs is belwo the desire amount, run items from the queue # if the amount of running rsyncs is below the desire amount, run items from the queue
if [[ ${#RUNNING_RSYNCS[@]} -lt ${RSYNC_PROCESSES} ]]; then
for torrent_hash in "${!TORRENT_QUEUE[@]}"; do for torrent_hash in "${!TORRENT_QUEUE[@]}"; do
# break out of the loop if we added enough jobs already
if [[ ${#RUNNING_RSYNCS[@]} -ge ${RSYNC_PROCESSES} ]]; then
break
fi
# make sure this torrent is not already being downloaded # make sure this torrent is not already being downloaded
if [[ ${RUNNING_RSYNCS[${torrent_hash}]+_} ]]; then if [[ ${RUNNING_RSYNCS[${torrent_hash}]+_} ]]; then
continue continue
@ -341,11 +344,10 @@ while true; do
fi fi
# start the download and record the PID # start the download and record the PID
rsync -hrvP --inplace "${SSH_USER}@${SSH_SERVER}:${SSH_SERVER_DOWNLOAD_PATH}/${torrent_name}" "${TORRENT_TMP_DOWNLOAD}/" > /dev/null & rsync -hrvP --inplace "${SSH_USER}@${SSH_SERVER}:\"${SSH_SERVER_DOWNLOAD_PATH}/${torrent_name}"\" "${TORRENT_TMP_DOWNLOAD}/" > /dev/null &
RUNNING_RSYNCS[${torrent_hash}]=$! RUNNING_RSYNCS[${torrent_hash}]=$!
fi fi
done done
fi
# checkup on the running rsyncs # checkup on the running rsyncs
for torrent_hash in "${!RUNNING_RSYNCS[@]}"; do for torrent_hash in "${!RUNNING_RSYNCS[@]}"; do