60d834463df7ece1eecbce4ed51270ce0ff372eb
[platform/upstream/coreutils.git] / tests / mv / setup
1 #! /bin/sh
2
3 # Use stat to find a writable directory on a file system different from that
4 # of the current directory.  If one is found, create a temporary directory
5 # inside it.
6
7 test "${CANDIDATE_TMP_DIRS+set}" = set \
8   || CANDIDATE_TMP_DIRS="$TMPDIR /tmp /var/tmp /usr/tmp $HOME"
9
10 other_partition_tmpdir=
11
12 dot_mount_point=`stat -c %d .`
13 for d in $CANDIDATE_TMP_DIRS; do
14
15   # Skip nonexistent directories.
16   test -d $d || continue
17
18   d_mount_point=`stat -L -c %d $d`
19
20   # Same partition?  Skip it.
21   test x$d_mount_point = x$dot_mount_point && continue
22
23   # See if we can create a directory in it.
24   if mkdir "$d/tmp$$" > /dev/null 2>&1; then
25     other_partition_tmpdir="$d/tmp$$"
26     break
27   fi
28
29 done
30
31 if test -z "$other_partition_tmpdir"; then
32   cat <<EOF 1>&2
33 **************************************
34 This test requires a writable directory on a different
35 disk partition, and I couldn't find one.  I tried these:
36   $CANDIDATE_TMP_DIRS
37 Set your environment variable CANDIDATE_TMP_DIRS to make
38 this test use a different list.
39 **************************************
40 EOF
41     #'
42 fi
43
44 test "$VERBOSE" = yes && set -x