btrfs-progs: tests: add helpers for creating temporary file

For convenience add helpers that will create a temporary file in the
$TMPDIR with a given additional tag in the name for later
identification.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2021-10-11 15:32:10 +02:00
parent 6e888a7a6c
commit ded1e50cd3

View File

@ -868,4 +868,28 @@ check_test_results()
fi
}
# Create at temporary file in $TMPDIR
# $1: optional identifier that'll be part of the name
_mktemp() {
local tmp
local name
name="btrfs-progs${1:+-$1}.XXXXXX"
_log "Create temporary file $name"
tmp=$(mktemp --tmpdir "$name")
echo -n "$tmp"
}
# Create at temporary directory in $TMPDIR
# $1: optional identifier that'll be part of the name
_mktemp_dir() {
local tmp
local name
name="btrfs-progs${1:+-$1}.XXXXXX"
_log "Create temporary file $name"
tmp=$(mktemp -d --tmpdir "$name")
echo -n "$tmp"
}
init_env