lsyncd/tests/directorymv.sh

62 lines
1.3 KiB
Bash
Raw Normal View History

#!/bin/bash
# test the case of directory being mv'ed and rm'ed. lsyncd 1.0 didn't handle this case well.
set -e
WORKSOURCE=$(mktemp -d)
WORKTARGET=$(mktemp -d)
PIDFILE=$(mktemp)
LOGFILE=$(mktemp)
2010-05-22 16:24:16 +00:00
echo $WORKSOURCE
echo $WORKTARGET
echo $PIDFILE
# populate the filesystem.
mkdir "${WORKSOURCE}"/a
mkdir "${WORKSOURCE}"/b
touch "${WORKSOURCE}"/a/f
touch "${WORKSOURCE}"/b/g
2010-05-22 16:24:16 +00:00
echo ./lsyncd --logfile "${LOGFILE}" --pidfile "${PIDFILE}" "${WORKSOURCE}" "${WORKTARGET}"
./lsyncd --logfile "${LOGFILE}" --pidfile "${PIDFILE}" "${WORKSOURCE}" "${WORKTARGET}"
2010-05-22 16:24:16 +00:00
LSYNCPID=$(cat "${PIDFILE}")
2010-05-22 16:24:16 +00:00
# try to wait until lsyncd starts and rsyncs initial file, hope 2s is enough.
sleep 2s
# move a file
2010-05-22 16:24:16 +00:00
echo "moving a directory"
mv "${WORKSOURCE}"/a "${WORKSOURCE}"/c
2010-05-22 16:24:16 +00:00
echo "create a file there"
touch "${WORKSOURCE}"/c/h
2010-05-22 16:24:16 +00:00
echo "and delete a directory"
#lsyncd 1.0 dies here
rm -r "${WORKSOURCE}"/b
2010-05-22 16:24:16 +00:00
echo "wait for events to trigger"
# try to wait until lsyncd does the job.
2010-05-22 16:24:16 +00:00
sleep 10s
echo "killing daemon"
if ! kill "${LSYNCPID}"; then
cat "${LOGFILE}"
diff -ur "${WORKSOURCE}" "${WORKTARGET}" || true
echo "kill failed"
exit 1
fi
sleep 1s
echo "log file contents"
cat "${LOGFILE}"
#this should be grep.
diff -ur "${WORKSOURCE}" "${WORKTARGET}"
2010-05-22 16:24:16 +00:00
#rm "${PIDFILE}"
#rm "${LOGFILE}"
#rm -rf "${WORKTARGET}"
#rm -rf "${WORKSOURCE}"