btrfs-progs: tests: add helper for creating local temporary file

Some tests don't use the /tmp temporary files and store it locally in
the test directory. To support NFS this needs to be created by a few
commands. To avoid accidental breakage add a convenience helper.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2022-09-15 15:58:07 +02:00
parent bd94a00de0
commit 500f826f31

View file

@ -870,4 +870,21 @@ _mktemp_dir() {
echo -n "$tmp"
}
# Create temporary file of the given name in the local test directory (eg. when
# it's a large image and not suitable for /tmp), this also supports NFS where
# the file needs to be created by regular user and made available for roo
# $1: file name
# $2: optional size (argument suitable for truncate)
_mktemp_local() {
local name
local size
name="$1"
size="${2:-0}"
_log "Create local temporary file $name"
rm -f -- "$name"
run_check truncate -s "$size" -- "$name"
run_check chmod a+w -- "$name"
}
init_env