other-fs-tmpdir 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/sh
  2. # Use stat to find a writable directory on a file system different from that
  3. # of the current directory. If one is found, create a temporary directory
  4. # inside it.
  5. # Copyright (C) 1998-2018 Free Software Foundation, Inc.
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. test "${CANDIDATE_TMP_DIRS+set}" = set \
  17. || CANDIDATE_TMP_DIRS="$TMPDIR /tmp /dev/shm /var/tmp /usr/tmp $HOME"
  18. other_partition_tmpdir=
  19. dot_mount_point=$(stat -c %d .)
  20. for d in $CANDIDATE_TMP_DIRS; do
  21. # Skip nonexistent directories.
  22. test -d "$d" || continue
  23. d_mount_point=$(stat -L -c %d "$d")
  24. # Same partition? Skip it.
  25. test "x$d_mount_point" = "x$dot_mount_point" && continue
  26. # See if we can create a directory in it.
  27. if mkdir "$d/tmp$$" > /dev/null 2>&1; then
  28. other_partition_tmpdir="$d/tmp$$"
  29. break
  30. fi
  31. done
  32. if test -z "$other_partition_tmpdir"; then
  33. skip_ \
  34. "requires a writable directory on a different disk partition,
  35. 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. fi
  40. test "$VERBOSE" = yes && set -x