2021-07-05 06:50:25 +00:00
|
|
|
#!/bin/bash
|
|
|
|
r_log "findutils" "Testing basic find stuff"
|
|
|
|
|
|
|
|
TMPDIR=/var/tmp/find
|
2023-11-21 08:23:44 +00:00
|
|
|
trap '/bin/rm -rf $TMPDIR' EXIT
|
2021-07-05 06:50:25 +00:00
|
|
|
|
|
|
|
[ -e $TMPDIR ] && rm -rf "$TMPDIR"
|
|
|
|
|
2021-07-06 20:16:01 +00:00
|
|
|
mkdir -p "$TMPDIR" || { r_log "findutils" "Can't create $TMPDIR"; exit "$FAIL"; }
|
2021-07-05 06:50:25 +00:00
|
|
|
touch "$TMPDIR/file1"
|
|
|
|
touch "$TMPDIR/file with a space"
|
|
|
|
r_log "findutils" "Check that find just works(tm)"
|
|
|
|
find "$TMPDIR" &> /dev/null
|
|
|
|
r_checkExitStatus $?
|
|
|
|
|
|
|
|
r_log "findutils" "Check that find fails for something that doesn't exist"
|
|
|
|
find "$TMPDIR/doesntexit" &> /dev/null
|
|
|
|
if [ $? -ne 1 ]; then
|
|
|
|
r_log "findutils" "Something wrong happened. Was the file there?"
|
|
|
|
else
|
|
|
|
r_checkExitStatus 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
r_log "findutils" "Prepare for xargs test"
|
|
|
|
LINES=$(find "$TMPDIR" -print0 | wc -l)
|
|
|
|
|
2021-07-06 20:16:01 +00:00
|
|
|
if [ "$LINES" -eq 0 ]; then
|
2021-07-05 06:50:25 +00:00
|
|
|
r_checkExitStatus 0
|
|
|
|
else
|
|
|
|
r_checkExitStatus 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
r_log "findutils" "Perform for xargs test"
|
|
|
|
find "$TMPDIR" -type f -print0 | xargs -0 ls &> /dev/null
|
|
|
|
r_checkExitStatus $?
|
|
|
|
|
|
|
|
r_log "findutils" "Perform for xargs test: fails with spaces in the name"
|
2021-07-06 20:16:01 +00:00
|
|
|
# shellcheck disable=SC2038
|
|
|
|
find "$TMPDIR" -type f | xargs ls &> /dev/null && { r_log "findutils" "Why did this get a 0 exit?"; exit "$FAIL"; }
|
|
|
|
ret_val=$?
|
2023-11-30 09:10:42 +00:00
|
|
|
if [ "$ret_val" -ne "0" ]; then
|
|
|
|
r_checkExitStatus 0
|
|
|
|
else
|
|
|
|
r_checkExitStatus 1
|
|
|
|
fi
|