2014-09-21 00:03:20 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2014-10-25 11:39:26 +02:00
|
|
|
set -ex
|
|
|
|
|
|
2014-09-21 00:03:20 +02:00
|
|
|
case $# in
|
|
|
|
|
0)
|
|
|
|
|
source_dir="."
|
|
|
|
|
binary_dir="."
|
|
|
|
|
;;
|
|
|
|
|
2)
|
|
|
|
|
source_dir=$1
|
|
|
|
|
binary_dir=$2
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "usage: $0 [source_dir] [binary_dir]"
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2014-09-25 19:25:57 +02:00
|
|
|
cmd="valgrind --suppressions="${source_dir}/valgrind.supp" --fullpath-after="$source_dir" --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes --track-origins=yes --error-exitcode=1 --quiet"
|
2014-09-21 00:03:20 +02:00
|
|
|
|
2014-12-01 22:02:19 +01:00
|
|
|
if [ ! -f "$XDG_CONFIG_HOME/mediafire-tools/config" -a ! -f ~/.config/mediafire-tools/config ]; then
|
2014-09-23 11:38:10 +02:00
|
|
|
echo "no configuration file found" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2014-10-25 11:39:26 +02:00
|
|
|
|
|
|
|
|
if [ `mount -t fuse.mediafire-fuse | wc -l` -ne 0 ]; then
|
|
|
|
|
echo "a fuse fs is already mounted" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2014-12-29 22:47:52 +01:00
|
|
|
$cmd "${binary_dir}/mediafire-fuse" -f -d /mnt &
|
2014-10-25 11:39:26 +02:00
|
|
|
fusepid="$!"
|
|
|
|
|
|
2014-12-05 13:05:33 +01:00
|
|
|
# wait for the file system to be mointed
|
2014-10-26 14:10:49 +01:00
|
|
|
for i in `seq 1 10`; do
|
|
|
|
|
sleep 1
|
2014-10-25 11:39:26 +02:00
|
|
|
if [ `mount -t fuse.mediafire-fuse | wc -l` -ne 0 ]; then
|
|
|
|
|
break;
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
2014-12-05 13:05:33 +01:00
|
|
|
# check if mounting was successful
|
2014-10-26 14:10:49 +01:00
|
|
|
if [ `mount -t fuse.mediafire-fuse | wc -l` -eq 0 ]; then
|
|
|
|
|
echo "cannot mount fuse" >&2
|
|
|
|
|
fusermount -u /mnt
|
|
|
|
|
wait "$fusepid"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2014-12-05 13:05:33 +01:00
|
|
|
# print tree
|
2014-10-25 11:39:26 +02:00
|
|
|
tree /mnt
|
|
|
|
|
|
2014-12-05 13:05:33 +01:00
|
|
|
# make new directory
|
|
|
|
|
mkdir "/mnt/test"
|
|
|
|
|
|
2014-12-19 10:15:31 +01:00
|
|
|
# FIXME: also test for moving and renaming of directories
|
2015-01-18 09:42:09 +01:00
|
|
|
# FIXME: also test for creating files and folder with special characters
|
|
|
|
|
# FIXME: also test for creating files and folder with name longer than 255
|
2014-12-19 10:15:31 +01:00
|
|
|
|
|
|
|
|
# create file in the root directory
|
|
|
|
|
echo foobar > "/mnt/foobar2"
|
|
|
|
|
|
|
|
|
|
# move the file to the new directory
|
|
|
|
|
mv /mnt/foobar2 /mnt/test/foobar
|
2014-12-05 13:05:33 +01:00
|
|
|
|
|
|
|
|
# wait a bit because above operation finishes before the release() call finished
|
|
|
|
|
sleep 5
|
|
|
|
|
|
|
|
|
|
# print tree
|
|
|
|
|
tree /mnt
|
|
|
|
|
|
|
|
|
|
# check content of new file
|
|
|
|
|
diff=`echo "foobar" | diff - "/mnt/test/foobar" >/dev/null 2>&1 && echo 0 || echo 1`
|
2014-11-14 13:07:01 +01:00
|
|
|
|
|
|
|
|
if [ $diff -ne 0 ]; then
|
2014-12-05 13:05:33 +01:00
|
|
|
printf "foobar" | diff - "/mnt/test/foobar" || true
|
2014-11-14 13:07:01 +01:00
|
|
|
fi
|
2014-10-27 14:17:03 +01:00
|
|
|
|
2014-12-05 13:05:33 +01:00
|
|
|
# delete directory and file inside
|
|
|
|
|
rm -rf "/mnt/test"
|
|
|
|
|
|
|
|
|
|
# print tree
|
|
|
|
|
tree /mnt
|
|
|
|
|
|
2014-10-27 14:17:03 +01:00
|
|
|
sleep 2
|
|
|
|
|
|
2014-10-25 11:39:26 +02:00
|
|
|
fusermount -u /mnt
|
|
|
|
|
|
|
|
|
|
wait "$fusepid"
|
2014-11-14 13:07:01 +01:00
|
|
|
valg=$?
|
|
|
|
|
|
|
|
|
|
if [ $diff -eq 0 -a $valg -eq 0 ]; then
|
|
|
|
|
exit 0
|
|
|
|
|
else
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|