File: eval_under_testloopfs

package info (click to toggle)
datalad 1.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,148 kB
  • sloc: python: 69,414; sh: 1,521; makefile: 220
file content (35 lines) | stat: -rwxr-xr-x 801 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
# Evaluate given command while running with DATALAD_TESTS_TEMP_DIR pointing to
# that temporary filesystem mounted using loop device

set -e

fs=${DATALAD_TESTS_TEMP_FS:-vfat}
size=${DATALAD_TESTS_TEMP_FSSIZE:-10}

set -u
tmp=$(mktemp -u "${TMPDIR:-/tmp}/datalad-fs-XXXXX")

echo "I: $fs of $size:  $tmp"

uid=$(id -u)
mntimage="$tmp.img"
mntpoint="$tmp"

dd if=/dev/zero "of=$mntimage" bs=1032192c "count=$size"
loop=$(sudo losetup --find --show "$mntimage")
sudo "mkfs.$fs" "$loop"
mkdir -p "$mntpoint"
sudo mount -o "uid=$uid" "$loop" "$mntpoint"

# Run the actual command
echo "I: running $*"
set +e
TMPDIR="$mntpoint" DATALAD_TESTS_TEMP_DIR="$mntpoint" "$@"
ret=$?

echo "I: done, unmounting"
sudo umount "$mntpoint"
sudo losetup -d "$loop"
rm -rf "$mntpoint" "$mntimage"
exit "$ret"