diff mbox series

[02/11] btrfs-progs: use $SUDO_HELPER in convert tests for temp files

Message ID f0a556e968d0b34b8305a6d751887d7712fc8305.1681938648.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: prep work for syncing files into kernel-shared | expand

Commit Message

Josef Bacik April 19, 2023, 9:13 p.m. UTC
While running make test-convert as a normal user I ran into this problem
where we do sudo find <blah> into a mktemp file that's created as the
normal user.  This results in find getting a EPERM while trying to mess
with that temp file.  Fix this by using $SUDO_HELPER for all the
tempfile manipulations so that root is the owner of everything, which
allows the convert tests to run as a normal user.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 tests/common.convert | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/tests/common.convert b/tests/common.convert
index 264972fa..160909eb 100644
--- a/tests/common.convert
+++ b/tests/common.convert
@@ -113,32 +113,32 @@  convert_test_perm() {
 
 	_assert_path "$1"
 	PERMTMP="$1"
-	FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert-filelist.XXXXXX)
+	FILES_LIST=$($SUDO_HELPER mktemp --tmpdir btrfs-progs-convert-filelist.XXXXXX)
 
 	run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/test" "bs=$nodesize" \
 		count=1 status=noxfer >/dev/null 2>&1
 	run_check_stdout $SUDO_HELPER find "$TEST_MNT" -type f ! -name 'image' -fprint "$FILES_LIST"
 	# Fix directory entries order
-	sort "$FILES_LIST" -o "$FILES_LIST"
-	for file in `cat "$FILES_LIST"` ;do
+	$SUDO_HELPER sort "$FILES_LIST" -o "$FILES_LIST"
+	for file in `$SUDO_HELPER cat "$FILES_LIST"` ;do
 		run_check_stdout $SUDO_HELPER getfacl --absolute-names "$file" >> "$PERMTMP"
 	done
-	rm -- "$FILES_LIST"
+	$SUDO_HELPER rm -- "$FILES_LIST"
 }
 # list acls of files on $TEST_MNT
 # $1: path where the acls will be stored
 convert_test_acl() {
 	local ACLSTMP
 	ACLTMP="$1"
-	FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert-filelist.XXXXXX)
+	FILES_LIST=$($SUDO_HELPER mktemp --tmpdir btrfs-progs-convert-filelist.XXXXXX)
 
 	run_check_stdout $SUDO_HELPER find "$TEST_MNT/acls" -type f -fprint "$FILES_LIST"
 	# Fix directory entries order
-	sort "$FILES_LIST" -o "$FILES_LIST"
-	for file in `cat "$FILES_LIST"`;do
+	$SUDO_HELPER sort "$FILES_LIST" -o "$FILES_LIST"
+	for file in `$SUDO_HELPER cat "$FILES_LIST"`;do
 		run_check_stdout $SUDO_HELPER getfattr --absolute-names -d "$file" >> "$ACLTMP"
 	done
-	rm -- "$FILES_LIST"
+	$SUDO_HELPER rm -- "$FILES_LIST"
 }
 
 # do conversion with given features and nodesize, fsck afterwards