Debian Codegraph @

tools/eval_under_testloopfs

raw
1 #!/bin/bash
2 # Evaluate given command while running with DATALAD_TESTS_TEMP_DIR pointing to
3 # that temporary filesystem mounted using loop device
4
5 set -e
6
7 fs=${DATALAD_TESTS_TEMP_FS:-vfat}
8 size=${DATALAD_TESTS_TEMP_FSSIZE:-10}
9
10 set -u
11 tmp=$(mktemp -u "${TMPDIR:-/tmp}/datalad-fs-XXXXX")
12
13 echo "I: $fs of $size: $tmp"
14
15 uid=$(id -u)
16 mntimage="$tmp.img"
17 mntpoint="$tmp"
18
19 dd if=/dev/zero "of=$mntimage" bs=1032192c "count=$size"
20 loop=$(sudo losetup --find --show "$mntimage")
21 sudo "mkfs.$fs" "$loop"
22 mkdir -p "$mntpoint"
23 sudo mount -o "uid=$uid" "$loop" "$mntpoint"
24
25 # Run the actual command
26 echo "I: running $*"
27 set +e
28 TMPDIR="$mntpoint" DATALAD_TESTS_TEMP_DIR="$mntpoint" "$@"
29 ret=$?
30
31 echo "I: done, unmounting"
32 sudo umount "$mntpoint"
33 sudo losetup -d "$loop"
34 rm -rf "$mntpoint" "$mntimage"
35 exit "$ret"