tarback/tests/common.sh

38 lines
1.2 KiB
Bash
Executable file

#!/bin/sh
create_directories() {
workdir="$(mktemp -d)"
mkdir -p "$workdir/source"
mkdir -p "$workdir/dest"
mkdir -p "$workdir/restore"
if [ $# -eq 1 ]; then
filename_len=$1
else
filename_len=255
fi
# generate a filename with every possible byte in it to test
# escaping, the only character not included is `/` since that is
# illegal for filenames (obviously)
echo 'Hello World!' > "$workdir/source/$(for i in $(seq 0 $filename_len); do printf '%x' "$i" | xxd -r -p; done | tr -d '/')"
echo "$workdir"
}
create_docker_volume() {
volumename="tarback-docker-volume-test-$(shuf -i 1000-9999 -n 1)"
# use shorter name because alpine runs into a filename length limit
if [ $# -eq 2 ]; then
workdir="$1"
filename="$2"
docker run --rm -i -v "$volumename:/mnt" alpine tee "/mnt/$filename" < "$workdir/source/$filename" 1>/dev/null
fi
echo "$volumename"
}
extract_docker_volume() {
volumename="$1"
workdir="$2"
filename="$3"
#docker run --rm -v "$volumename:/mnt" alpine find /
docker run --rm -v "$volumename:/mnt" alpine cat "/mnt/$filename" > "$workdir/restore/$filename"
}