1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
#!/bin/bash
#
# Copyright 2011 Red Hat Inc., Durham, North Carolina.
# All Rights Reserved.
#
# Authors:
# Daniel Kopecek <dkopecek@redhat.com>
# Tomas Heinrich <theinric@redhat.com>
function gen_tree {
echo "Generating tree for traversal" >&2
mkdir -p $ROOT/{d1/{d11/d111,d12},d2/d21}
touch $ROOT/{d1/{d11/{d111/f1111,f111,f112,f113},d12/f121,f11},d2/{d21/f211,f21}}
}
function oval_fts {
echo "=== $1 ==="
shift
./oval_fts_list "$@" | sort | tee ${tmpdir}/oval_fts_list.out | \
sed "s|${ROOT}/||" | tr '\n' ',' > ${tmpdir}/oval_fts_list.out2
if [ $? -ne 0 ]; then
echo "oval_fts_list failed"
return 2
fi
shift 4
echo -e "expected result:\n$1\noval_fts_list.out2:"
cat ${tmpdir}/oval_fts_list.out2
echo
if [ "$(cat ${tmpdir}/oval_fts_list.out2 | openssl md5)" == \
"$(echo -n $1 | openssl md5)" ]; then
return 0
else
return 1
fi
}
set -e -o pipefail
name=$(basename $0 .sh)
tmpdir=$(mktemp -t -d "${name}.XXXXXX")
ROOT=${tmpdir}/ftsroot
echo "Temp dir: ${tmpdir}."
gen_tree $ROOT
while read args; do
[ -z "${args%%#*}" ] && continue
eval oval_fts $args
done <<EOF
test1 \
'' '' \
'((filepath :operation 5) "'$ROOT'/d1/d12/f121")' \
'((behaviors :max_depth "-1" :recurse "symlinks and directories" :recurse_direction "none" :recurse_file_system "all"))' \
d1/d12/f121,
test2 \
'' '' \
'((filepath :operation 11) "^'$ROOT'/d1/.*/f1111")' \
'((behaviors :max_depth "-1" :recurse "symlinks and directories" :recurse_direction "none" :recurse_file_system "all"))' \
d1/d11/d111/f1111,
test3 \
'((path :operation 5) "'$ROOT'/d2")' \
'((filename :operation 5) "f21")' \
'' \
'((behaviors :max_depth "-1" :recurse "symlinks and directories" :recurse_direction "none" :recurse_file_system "all"))' \
d2/f21,
test4 \
'((path :operation 5) "'$ROOT'/d1/d11")' \
'((filename :operation 11) "^f11[23]$")' \
'' \
'((behaviors :max_depth "-1" :recurse "symlinks and directories" :recurse_direction "none" :recurse_file_system "all"))' \
d1/d11/f112,d1/d11/f113,
test5 \
'((path :operation 11) "^'$ROOT'/d1/d1[12]$")' \
'((filename :operation 11) "^f..1$")' \
'' \
'((behaviors :max_depth "-1" :recurse "symlinks and directories" :recurse_direction "none" :recurse_file_system "all"))' \
d1/d11/f111,d1/d12/f121,
test6 \
'((path :operation 11) "^'$ROOT'/d1/.*")' \
'((filename :operation 5) "f1111")' \
'' \
'((behaviors :max_depth "-1" :recurse "symlinks and directories" :recurse_direction "none" :recurse_file_system "all"))' \
d1/d11/d111/f1111,
test7 \
'((path :operation 5) "'$ROOT'/d1")' \
'((filename :operation 5) "f112")' \
'' \
'((behaviors :max_depth "-1" :recurse "symlinks and directories" :recurse_direction "down" :recurse_file_system "all"))' \
d1/d11/f112,
test8 \
'((path :operation 5) "'$ROOT'/d1")' \
'((filename :operation 11) "^f.*1$")' \
'' \
'((behaviors :max_depth "1" :recurse "symlinks and directories" :recurse_direction "down" :recurse_file_system "all"))' \
d1/d11/f111,d1/d12/f121,d1/f11,
test9 \
'((path :operation 5) "'$ROOT'/d1/d11/d111")' \
'((filename :operation 5) "f11")' \
'' \
'((behaviors :max_depth "3" :recurse "symlinks and directories" :recurse_direction "up" :recurse_file_system "all"))' \
d1/f11,
test10 \
'((path :operation 5) "'$ROOT'/d2")' \
'((filename :operation 11) "^f21.*$")' \
'' \
'((behaviors :max_depth "-1" :recurse "symlinks and directories" :recurse_direction "down" :recurse_file_system "all"))' \
d2/d21/f211,d2/f21,
test11 \
'((path :operation 5) "'$ROOT'/d2")' \
'((filename :operation 11) "^f21.*$")' \
'' \
'((behaviors :max_depth "-1" :recurse "symlinks" :recurse_direction "down" :recurse_file_system "all"))' \
d2/f21,
test12 \
'((path :operation 5) "'$ROOT'/d1")' \
'((filename :operation 5))' \
'' \
'((behaviors :max_depth "0" :recurse "symlinks and directories" :recurse_direction "none" :recurse_file_system "all"))' \
d1/,
test13 \
'((path :operation 5) "'$ROOT'/d1")' \
'((filename :operation 5))' \
'' \
'((behaviors :max_depth "0" :recurse "symlinks and directories" :recurse_direction "down" :recurse_file_system "all"))' \
d1/,
test14 \
'((path :operation 5) "'$ROOT'/d1")' \
'((filename :operation 5))' \
'' \
'((behaviors :max_depth "0" :recurse "symlinks and directories" :recurse_direction "up" :recurse_file_system "all"))' \
d1/,
test15 \
'((path :operation 5) "'$ROOT'/d1")' \
'((filename :operation 5))' \
'' \
'((behaviors :max_depth "1" :recurse "symlinks and directories" :recurse_direction "down" :recurse_file_system "all"))' \
d1/,d1/d11/,d1/d12/,
test16 \
'((path :operation 5) "'$ROOT'/d1/d11")' \
'((filename :operation 5))' \
'' \
'((behaviors :max_depth "1" :recurse "symlinks and directories" :recurse_direction "up" :recurse_file_system "all"))' \
d1/,d1/d11/,
test17 \
'((path :operation 5) "'$ROOT'/d1/d11")' \
'((filename :operation 5))' \
'' \
'((behaviors :max_depth "-1" :recurse "symlinks and directories" :recurse_direction "down" :recurse_file_system "all"))' \
d1/d11/,d1/d11/d111/,
# support for empty string as a pattern in 'filename' entity
test18 \
'((path :operation 5) "'$ROOT'/d2")' \
'((filename :operation 11) "")' \
'' \
'((behaviors :max_depth "-1" :recurse "symlinks and directories" :recurse_direction "none" :recurse_file_system "all"))' \
d2/f21,
# don't return nonexistent filepath
test19 \
'' '' \
'((filepath :operation 5) "/nonexistent")' \
'((behaviors :max_depth "-1" :recurse "symlinks and directories" :recurse_direction "none" :recurse_file_system "all"))' \
# intentionally left blank
# test for a regression caused by the errno check that follows calls to fts_open()
test20 \
'((path :operation 5) "'$ROOT'/d1/d11/d111")' \
'((filename :operation 5) "f1111")' \
'' \
'((behaviors :max_depth "-1" :recurse "directories" :recurse_direction "down" :recurse_file_system "local"))' \
d1/d11/d111/f1111,
EOF
rm -rf $tmpdir
|